Jason Chang
/
9v1
Add I2CSlave to ov580 master.
Diff: main.cpp
- Revision:
- 7:9c77eaad5102
- Parent:
- 6:85d9ad912c14
- Child:
- 8:10ffd42a3921
--- a/main.cpp Thu Oct 25 23:06:06 2018 +0000 +++ b/main.cpp Mon Oct 29 00:04:10 2018 +0000 @@ -1,4 +1,18 @@ +#define TWIS1_ENABLED 1 +#define TWIS0_ENABLED 0 +#define TWIS_ENABLED 1 +#define TWI0_ENABLED 1 +#define TWI1_ENABLED 0 +#define TWI0_USE_EASY_DMA 1 +#define TWI1_USE_EASY_DMA 1 +#define TWI_DEFAULT_CONFIG_FREQUENCY 104857600 +#define ARDUINO_A4_PIN 14 +#define ARDUINO_A5_PIN 15 + + #include "mbed.h" +//#include <nrfx_config.h> need SDK config instead +//#include "sdk_config.h" not needed now /* FEATURE REQUIREMENTS @@ -48,20 +62,25 @@ */ -/* TEST THIS AT SOME POINT */ +#if (TWIS0_ENABLED == 1) +#error TWIS0 is congigured wrong +#endif + +#if (TWIS1_ENABLED == 0) +#error TWIS1 is off +#endif -/* -if ( bEnable ) -{ NRF_TWI1->ENABLE = TWI_ENABLE_ENABLE_Enabled << TWI_ENABLE_ENABLE_Pos; -NRF_TWI0->ENABLE = TWI_ENABLE_ENABLE_Enabled << TWI_ENABLE_ENABLE_Pos; -} -else -{ NRF_TWI1->ENABLE = TWI_ENABLE_ENABLE_Disabled << TWI_ENABLE_ENABLE_Pos; - NRF_TWI0->ENABLE = TWI_ENABLE_ENABLE_Disabled << TWI_ENABLE_ENABLE_Pos; } -*/ +#if (TWIS_ENABLED == 0) +#error TWIS is off +#endif -// Probably something like this for TWIS -// NRF_TWIS0->ENABLE = TWIS_ENABLE_ENABLE_Enabled << TWIS_ENABLE_ENABLE_Pos; +#if (TWI0_ENABLED == 0) +#error TWI0 is off +#endif + +#if (TWI1_ENABLED == 1) +#error TWI1 is congigured wrong +#endif /* DEFINES */ @@ -88,7 +107,6 @@ #define ledGreen p17 #define ledBlue p13 - /* THREAD */ EventQueue queue; @@ -111,11 +129,15 @@ DigitalOut pwm_1_output(pwm_1_pin,0); // GPIO 4 // Initialize inputs -DigitalIn strobe0(p23,PullNone); -DigitalIn strobe1(p24,PullNone); +DigitalIn strobe0(strobe_flood,PullNone); +DigitalIn strobe1(strobe_dot,PullNone); DigitalIn vcselFault(p25,PullNone); DigitalIn killVcsel(p26,PullNone); // vcselFault is 1V8 instead of 3V3 +DigitalInOut ovsda(ov580_sda); + + + /* REGISTERS */ static uint8_t LM36011_addr = 0x64 << 1; //0xC8 @@ -148,7 +170,7 @@ char flashBrightness_flood[2] = {brightness_reg,level_flood_max}; /* I2C */ -//I2CSlave ov_I2C(ov580_sda,ov580_scl); +I2CSlave ov_I2C(ov580_sda,ov580_scl); I2C flood_I2C(flood_sda,flood_scl); I2C dot_I2C(dot_sda,dot_scl); @@ -156,7 +178,7 @@ /* VARIABLES */ bool stacked = false; bool emitter_status_dot = false; -//char rcv_buffer[3] = {0,0,0}; +char rcv_buffer[3] = {0,0,0}; bool dot_on = false; bool flood_on = false; bool once = false; @@ -195,8 +217,6 @@ void write_once() { - // write dot - /* if(stacked) { write_pulsed(); } else { @@ -208,7 +228,7 @@ write_off(); } } - */ + write_pulsed(); dot_on = false; flood_on = false; @@ -266,7 +286,7 @@ } // TODOS // -// P0 Get illumination working +// DONE P0 Get illumination working // P0 Get in app working // P0 Get watchdog time working // P1 Bluetooth OTA updates @@ -277,6 +297,8 @@ // main() runs in its own thread in the OS int main() { + ovsda.output(); + ovsda.mode(OpenDrain); wait(5); Thread eventThread(osPriorityHigh);; @@ -289,12 +311,12 @@ int_strobe_flood.fall(&lightsOn); // set I2C Frequency to 400kHz - flood_I2C.frequency(400000); - dot_I2C.frequency(400000); - //ov_I2C.frequency(400000); + //flood_I2C.frequency(400000); not needed cause of set defaults + //dot_I2C.frequency(400000); not needed cause of set defaults + ov_I2C.frequency(400000); //TODO get i2c writes working - //ov_I2C.address(0x10); + ov_I2C.address(0xC0); // write safety flood_I2C.write(LM36011_addr,lmSafety,2,false); @@ -304,11 +326,11 @@ flood_I2C.write(LM36011_addr,flashBrightness_flood,2,false); dot_I2C.write(LM36011_addr,flashBrightness_dot,2,false); - //char read_buff[2] = {0,0}; + char read_buff[2] = {0,0}; while (true) { - /* + int i = ov_I2C.receive(); switch(i) { @@ -329,9 +351,9 @@ for (int k = 0; k < 3; k++) rcv_buffer[i]=0; - */ - green = !stacked; - red = stacked; + + //green = !stacked; + //red = stacked; } }