Browse Source

Use hardware structure for interrupt numbers

main
PaulStoffregen 7 years ago
parent
commit
c634390cdf
2 changed files with 46 additions and 2 deletions
  1. +30
    -2
      WireKinetis.cpp
  2. +16
    -0
      WireKinetis.h

+ 30
- 2
WireKinetis.cpp View File

@@ -296,13 +296,13 @@ void TwoWire::begin(uint8_t address)
port.A1 = address << 1;
slave_mode = 1;
port.C1 = I2C_C1_IICEN | I2C_C1_IICIE;
NVIC_ENABLE_IRQ(IRQ_I2C0);
NVIC_ENABLE_IRQ(hardware.irq);
}

void TwoWire::end()
{
if (!(hardware.clock_gate_register & hardware.clock_gate_mask)) return;
NVIC_DISABLE_IRQ(IRQ_I2C0);
NVIC_DISABLE_IRQ(hardware.irq);
// TODO: should this try to create a stop condition??
port.C1 = 0;
volatile uint32_t *reg;
@@ -313,10 +313,34 @@ void TwoWire::end()
hardware.clock_gate_register &= ~hardware.clock_gate_mask;
}

#ifdef WIRE_IMPLEMENT_WIRE
void i2c0_isr(void)
{
Wire.isr();
}
#endif

#ifdef WIRE_IMPLEMENT_WIRE1
void i2c1_isr(void)
{
Wire1.isr();
}
#endif

#ifdef WIRE_IMPLEMENT_WIRE2
void i2c2_isr(void)
{
Wire2.isr();
}
#endif

#ifdef WIRE_IMPLEMENT_WIRE3
void i2c3_isr(void)
{
Wire3.isr();
}
#endif


void TwoWire::isr(void)
{
@@ -638,6 +662,7 @@ const TwoWire::I2C_Hardware_t TwoWire::i2c0_hardware = {
19, 16, 33, 7, 47,
2, 2, 5, 7, 2,
#endif
IRQ_I2C0
};

TwoWire Wire(KINETIS_I2C0, TwoWire::i2c0_hardware);
@@ -665,6 +690,7 @@ const TwoWire::I2C_Hardware_t TwoWire::i2c1_hardware = {
37, 255, 255, 255, 255,
2, 0, 0, 0, 0,
#endif
IRQ_I2C1
};

TwoWire Wire1(KINETIS_I2C1, TwoWire::i2c1_hardware);
@@ -682,6 +708,7 @@ const TwoWire::I2C_Hardware_t TwoWire::i2c2_hardware = {
3, 26, 255, 255, 255,
5, 5, 0, 0, 0,
#endif
IRQ_I2C2
};

#endif // WIRE_IMPLEMENT_WIRE2
@@ -697,6 +724,7 @@ const TwoWire::I2C_Hardware_t TwoWire::i2c3_hardware = {
57, 255, 255, 255, 255,
2, 0, 0, 0, 0,
#endif
IRQ_I2C3
};

#endif // WIRE_IMPLEMENT_WIRE3

+ 16
- 0
WireKinetis.h View File

@@ -84,6 +84,7 @@ public:
uint8_t sda_mux[5];
uint8_t scl_pin[5];
uint8_t scl_mux[5];
IRQ_NUMBER_t irq;
} I2C_Hardware_t;
static const I2C_Hardware_t i2c0_hardware;
static const I2C_Hardware_t i2c1_hardware;
@@ -206,10 +207,25 @@ private:
void (*user_onReceive)(int);
//void sda_rising_isr(void);
friend void i2c0_isr(void);
friend void i2c1_isr(void);
friend void i2c2_isr(void);
friend void i2c3_isr(void);
friend void sda_rising_isr(void);
};

#ifdef WIRE_IMPLEMENT_WIRE
extern TwoWire Wire;
#endif
#ifdef WIRE_IMPLEMENT_WIRE1
extern TwoWire Wire1;
#endif
#ifdef WIRE_IMPLEMENT_WIRE2
extern TwoWire Wire2;
#endif
#ifdef WIRE_IMPLEMENT_WIRE3
extern TwoWire Wire3;
#endif


class TWBRemulation
{

Loading…
Cancel
Save