Add I2CSlave to ov580 master.

Dependencies:   MorseGenerator2

Files at this revision

API Documentation at this revision

Comitter:
jasoncha
Date:
Thu May 02 21:55:46 2019 +0000
Parent:
25:eac4de6661a9
Commit message:
Publish it for Clayton to test.

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-os-retarget-segger-rtt.lib Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Tue Apr 23 23:31:21 2019 +0000
+++ b/main.cpp	Thu May 02 21:55:46 2019 +0000
@@ -12,6 +12,7 @@
 
 #include "mbed.h"
 #include "MorseGenerator.h"
+#include "SEGGER_RTT.h"
 //#include <nrfx_config.h>  need SDK config instead
 //#include "sdk_config.h" not needed now
 
@@ -176,8 +177,8 @@
 
 /*          REGISTERS       */
 static uint8_t LM36011_addr = 0x64 << 1;  //0xC8
-static int NRF_I2CSlave_addr = 0x20;
-static uint32_t NRF_I2CSlave_frequency = 300000;
+int NRF_I2CSlave_addr = 0x20;
+int NRF_I2CSlave_frequency = 300000;
 
 
 // register names
@@ -240,11 +241,13 @@
 int stacked_counter = 0;
 bool read_fail;
 
-#define MY_BUF_SIZE 8
+#define MY_BUF_SIZE 1
 
 int i2c_recv = 0;
-char i2c_tx_buff[MY_BUF_SIZE] = {'7','6','5','4','3','2','1','0'};
+char i2c_tx_buff[MY_BUF_SIZE];
 char i2c_rx_buff[MY_BUF_SIZE];
+char *i2c_tx_buff_ptr =  (char *)0x20000000;
+char *i2c_rx_buff_ptr =  (char *)0x20000008;
 char i2c_tx_data = 0x55;
 char i2c_rx_data = 0x00;
 
@@ -513,11 +516,47 @@
     Thread eventThread(osPriorityHigh);
     eventThread.start(callback(&queue, &EventQueue::dispatch_forever));
 
-    NRF_TWIS0->ENABLE = 0;
-    NRF_TWIS1->ENABLE = 1;
+     unsigned int index = 0;
+     SEGGER_RTT_printf(index, "%s\n", "main, Hello NRF58-DK\n");
+ 
     ov580_I2C.frequency(NRF_I2CSlave_frequency);  
     ov580_I2C.address(NRF_I2CSlave_addr);
- //   ov580_I2C.stop();  
+
+     for (int i=0; i<MY_BUF_SIZE; i++) {
+        *(i2c_tx_buff_ptr+i) = 0xaa;
+    }
+    for (int i=0; i<MY_BUF_SIZE; i++) {
+        *(i2c_rx_buff_ptr+i) = 0x55;
+    }
+    
+    NRF_TWIS0->ADDRESS[1] = NRF_I2CSlave_addr;
+    NRF_TWIS0->ADDRESS[0] = NRF_I2CSlave_addr;
+    NRF_TWIS0->TXD.PTR = (uint32_t)i2c_tx_buff_ptr;
+    NRF_TWIS0->TXD.MAXCNT = MY_BUF_SIZE;
+    NRF_TWIS0->RXD.PTR = (uint32_t)i2c_rx_buff_ptr;
+    NRF_TWIS0->RXD.MAXCNT = MY_BUF_SIZE;   
+   
+    NRF_TWIS1->ADDRESS[1] = NRF_I2CSlave_addr;
+    NRF_TWIS1->ADDRESS[0] = NRF_I2CSlave_addr;   
+    NRF_TWIS1->TXD.PTR = (uint32_t)i2c_tx_buff_ptr;
+    NRF_TWIS1->TXD.MAXCNT = MY_BUF_SIZE;
+    NRF_TWIS1->RXD.PTR = (uint32_t)i2c_rx_buff_ptr;
+    NRF_TWIS1->RXD.MAXCNT = MY_BUF_SIZE;
+    
+    SEGGER_RTT_printf(index, "CONFIG0: %d\n", NRF_TWIS0->CONFIG);
+    SEGGER_RTT_printf(index, "CONFIG1: %d\n", NRF_TWIS1->CONFIG);
+    NRF_TWIS0->ENABLE = 1;
+    NRF_TWIS1->ENABLE = 1;
+    NRF_TWIS0->TASKS_PREPARERX = 1;
+    NRF_TWIS0->TASKS_PREPARETX = 1;
+    NRF_TWIS1->TASKS_PREPARERX = 1;
+    NRF_TWIS1->TASKS_PREPARETX = 1;
+    
+    NRF_TWIS0->TASKS_RESUME = 1;
+    NRF_TWIS1->TASKS_RESUME = 1;
+   
+//    ov580_I2C.stop();
+    
     red = 1;
     green = 1;
     blue = 1; 
@@ -533,9 +572,12 @@
     dot_timer.start();
     flood_timer.start();
     
-    MorseGenerator morse = MorseGenerator(morse_callback);
-    morse.transmit(version_number);
-  
+   #if 0
+   MorseGenerator morse = MorseGenerator(morse_callback);
+   morse.transmit(version_number);
+   #endif
+ 
+
     while(!in_app) {
         wait(.1);
     }
@@ -556,34 +598,37 @@
     dot_I2C.write(LM36011_addr,flashBrightness_dot,2,false);
 #endif
 
+    blue = 0;
+    SEGGER_RTT_printf(index, "%s\n", "Before loop");
+    
     while (true) {
-       blue = 0;
     // Handle I2C slave receive from OV580 master transmit
+  //      SEGGER_RTT_printf(index, "%s\n","ov580_I2C.receive()");
         i2c_recv = ov580_I2C.receive();
+        if (i2c_recv != 0) {
+            SEGGER_RTT_printf(index, "%d\n",i2c_recv);
+        }
         switch(i2c_recv) {
             case I2CSlave::ReadAddressed:
+            SEGGER_RTT_printf(index, "%s\n", "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:
+            SEGGER_RTT_printf(index, "%s\n", "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:
+            SEGGER_RTT_printf(index, "%s\n", "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;
@@ -594,7 +639,7 @@
             break;
         }
     
-
+#if 0
     // Handle flood and dot illuminators
         if(dot_timer_number > 700 && dot_timer_number < 1499) {
             dot_current_setting = dot_one_ms;
@@ -645,7 +690,7 @@
 
         level_flood_max_dec = uint32_t(flood_current_setting/divisor);
         level_flood_max = (((level_flood_max_dec / 16) << 4) & 0xf0) |
-                          ((level_flood_max_dec % 16) & 0x0f);
+                         ((level_flood_max_dec % 16) & 0x0f);
 
 
         flashBrightness_flood[1] = level_flood_max;
@@ -653,8 +698,9 @@
         flood_I2C.write(LM36011_addr,flashBrightness_flood,2,false);
 
         wait(.01);
-       
+             
         silego_check_status();
+#endif
         
         
     }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-os-retarget-segger-rtt.lib	Thu May 02 21:55:46 2019 +0000
@@ -0,0 +1,1 @@
+https://github.com/0x6d61726b/mbed-os-retarget-segger-rtt/#648b5440bd2744c5356c73b9bfdf8081ca65d79a