Jason Chang
/
9v1
Add I2CSlave to ov580 master.
Diff: main.cpp
- Revision:
- 25:eac4de6661a9
- Parent:
- 24:8664847e79d2
- Child:
- 26:9ad740976a72
--- a/main.cpp Thu Apr 04 22:43:49 2019 +0000 +++ b/main.cpp Tue Apr 23 23:31:21 2019 +0000 @@ -176,6 +176,9 @@ /* REGISTERS */ static uint8_t LM36011_addr = 0x64 << 1; //0xC8 +static int NRF_I2CSlave_addr = 0x20; +static uint32_t NRF_I2CSlave_frequency = 300000; + // register names static uint8_t enable_reg = 0x01; @@ -237,6 +240,14 @@ int stacked_counter = 0; bool read_fail; +#define MY_BUF_SIZE 8 + +int i2c_recv = 0; +char i2c_tx_buff[MY_BUF_SIZE] = {'7','6','5','4','3','2','1','0'}; +char i2c_rx_buff[MY_BUF_SIZE]; +char i2c_tx_data = 0x55; +char i2c_rx_data = 0x00; + int dot_timer_number; int flood_timer_number; @@ -499,9 +510,20 @@ // main() runs in its own thread in the OS int main() { - Thread eventThread(osPriorityHigh);; + Thread eventThread(osPriorityHigh); eventThread.start(callback(&queue, &EventQueue::dispatch_forever)); + NRF_TWIS0->ENABLE = 0; + NRF_TWIS1->ENABLE = 1; + ov580_I2C.frequency(NRF_I2CSlave_frequency); + ov580_I2C.address(NRF_I2CSlave_addr); + // ov580_I2C.stop(); + red = 1; + green = 1; + blue = 1; + in_app = true; // TODO(Jasoncha) check with Clayton + int i2c_return = -1; + // set interrupts int_strobe_dot.rise(&dot_check); int_strobe_flood.rise(&flood_check); @@ -513,17 +535,18 @@ MorseGenerator morse = MorseGenerator(morse_callback); morse.transmit(version_number); - + while(!in_app) { wait(.1); } - + silego = 1; - + + #if 0 //TODO(jasoncha) check with Clayton // write safety flood_I2C.write(LM36011_addr,lmSafety,2,false); dot_I2C.write(LM36011_addr,lmSafety,2,false); - + // write torch flood_I2C.write(LM36011_addr,torchBrightness_both,2,false); dot_I2C.write(LM36011_addr,torchBrightness_both,2,false); @@ -531,9 +554,48 @@ // write brightness flood_I2C.write(LM36011_addr,flashBrightness_flood,2,false); dot_I2C.write(LM36011_addr,flashBrightness_dot,2,false); +#endif while (true) { + blue = 0; + // Handle I2C slave receive from OV580 master transmit + i2c_recv = ov580_I2C.receive(); + switch(i2c_recv) { + case I2CSlave::ReadAddressed: + red = 0; + blue = 1; +// NRF_TWIS1->TXD.PTR = (uint32_t)i2c_tx_buff; +// NRF_TWIS1->TXD.MAXCNT = MY_BUF_SIZE; +// ov580_I2C.write(i2c_tx_buff, strlen(i2c_tx_buff) + 1); + i2c_return = ov580_I2C.write(&i2c_tx_data, 1); + break; + + case I2CSlave::WriteGeneral: + green = 0; + blue = 1; +// NRF_TWIS1->RXD.PTR = (uint32_t)i2c_rx_buff; +// NRF_TWIS1->RXD.MAXCNT = MY_BUF_SIZE; +// ov580_I2C.read(i2c_rx_buff, MY_BUF_SIZE); + i2c_return = ov580_I2C.read(&i2c_rx_data, 1); + break; + + case I2CSlave::WriteAddressed: + green = 0; + blue = 1; +// NRF_TWIS1->RXD.PTR = (uint32_t)i2c_rx_buff; +// NRF_TWIS1->RXD.MAXCNT = MY_BUF_SIZE; +// ov580_I2C.read(i2c_rx_buff, MY_BUF_SIZE); + i2c_return = ov580_I2C.read(&i2c_rx_data, 1); + break; + + case I2CSlave::NoData: + // blue = 1; + ov580_I2C.stop(); + break; + } + + // Handle flood and dot illuminators if(dot_timer_number > 700 && dot_timer_number < 1499) { dot_current_setting = dot_one_ms; @@ -593,6 +655,8 @@ wait(.01); silego_check_status(); + + } }