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

port.A1 = address << 1; port.A1 = address << 1;
slave_mode = 1; slave_mode = 1;
port.C1 = I2C_C1_IICEN | I2C_C1_IICIE; port.C1 = I2C_C1_IICEN | I2C_C1_IICIE;
NVIC_ENABLE_IRQ(IRQ_I2C0);
NVIC_ENABLE_IRQ(hardware.irq);
} }


void TwoWire::end() void TwoWire::end()
{ {
if (!(hardware.clock_gate_register & hardware.clock_gate_mask)) return; 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?? // TODO: should this try to create a stop condition??
port.C1 = 0; port.C1 = 0;
volatile uint32_t *reg; volatile uint32_t *reg;
hardware.clock_gate_register &= ~hardware.clock_gate_mask; hardware.clock_gate_register &= ~hardware.clock_gate_mask;
} }


#ifdef WIRE_IMPLEMENT_WIRE
void i2c0_isr(void) void i2c0_isr(void)
{ {
Wire.isr(); 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) void TwoWire::isr(void)
{ {
19, 16, 33, 7, 47, 19, 16, 33, 7, 47,
2, 2, 5, 7, 2, 2, 2, 5, 7, 2,
#endif #endif
IRQ_I2C0
}; };


TwoWire Wire(KINETIS_I2C0, TwoWire::i2c0_hardware); TwoWire Wire(KINETIS_I2C0, TwoWire::i2c0_hardware);
37, 255, 255, 255, 255, 37, 255, 255, 255, 255,
2, 0, 0, 0, 0, 2, 0, 0, 0, 0,
#endif #endif
IRQ_I2C1
}; };


TwoWire Wire1(KINETIS_I2C1, TwoWire::i2c1_hardware); TwoWire Wire1(KINETIS_I2C1, TwoWire::i2c1_hardware);
3, 26, 255, 255, 255, 3, 26, 255, 255, 255,
5, 5, 0, 0, 0, 5, 5, 0, 0, 0,
#endif #endif
IRQ_I2C2
}; };


#endif // WIRE_IMPLEMENT_WIRE2 #endif // WIRE_IMPLEMENT_WIRE2
57, 255, 255, 255, 255, 57, 255, 255, 255, 255,
2, 0, 0, 0, 0, 2, 0, 0, 0, 0,
#endif #endif
IRQ_I2C3
}; };


#endif // WIRE_IMPLEMENT_WIRE3 #endif // WIRE_IMPLEMENT_WIRE3

+ 16
- 0
WireKinetis.h View File

uint8_t sda_mux[5]; uint8_t sda_mux[5];
uint8_t scl_pin[5]; uint8_t scl_pin[5];
uint8_t scl_mux[5]; uint8_t scl_mux[5];
IRQ_NUMBER_t irq;
} I2C_Hardware_t; } I2C_Hardware_t;
static const I2C_Hardware_t i2c0_hardware; static const I2C_Hardware_t i2c0_hardware;
static const I2C_Hardware_t i2c1_hardware; static const I2C_Hardware_t i2c1_hardware;
void (*user_onReceive)(int); void (*user_onReceive)(int);
//void sda_rising_isr(void); //void sda_rising_isr(void);
friend void i2c0_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); friend void sda_rising_isr(void);
}; };


#ifdef WIRE_IMPLEMENT_WIRE
extern TwoWire 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 class TWBRemulation
{ {

Loading…
Cancel
Save