Sony's LANC camera control protocol project.
Dependencies: aconno_LANC aconno_bsp aconno_SEGGER_RTT
Diff: main.cpp
- Revision:
- 4:6560e2966186
- Parent:
- 3:eb5b87baf6cf
- Child:
- 5:ecb7712b0825
--- a/main.cpp Wed Nov 01 12:13:07 2017 +0000 +++ b/main.cpp Wed Nov 01 12:52:30 2017 +0000 @@ -21,33 +21,28 @@ * Bitovi na I2S bus idu od MSBa do LSBa */ -#define REC_CMD_1 (0xE7) // 0xE7 or 0x18 -#define REC_CMD_2 (0xCC) // 0xCC or 0x33 - #define LANC_COMMAND_PIN (p2) // Pin connected to Tr to pull lanc bus down/up 2/26 #define LANC_PIN (p3) // Lanc bus pin (to scan for START/STOP bits) 3/25 -DigitalOut led(p22); DigitalOut alive(p24); uint8_t normalCommand[MY_BUF_SIZE] __attribute__ ((aligned (32))) = {LANC_L,LANC_L,LANC_L,LANC_H, LANC_H,LANC_L,LANC_L,LANC_L}; -//uint8_t startStop[MY_BUF_SIZE] __attribute__ ((aligned (32))) = {LANC_L,LANC_L,LANC_H,LANC_H,LANC_L,LANC_L,LANC_H,LANC_H_L}; -//uint8_t normalCommand[MY_BUF_SIZE] __attribute__ ((aligned (32))) = {LANC_L,LANC_H,LANC_H,LANC_L, LANC_L,LANC_H,LANC_H,LANC_H}; +uint8_t specialCommand[MY_BUF_SIZE] __attribute__ ((aligned (32))) = {LANC_L,LANC_L,LANC_L,LANC_H, LANC_L,LANC_H,LANC_L,LANC_L}; uint8_t startStop[MY_BUF_SIZE] __attribute__ ((aligned (32))) = {LANC_H,LANC_H,LANC_L,LANC_L,LANC_H,LANC_H,LANC_L,LANC_L}; +uint8_t zoomIn[MY_BUF_SIZE] __attribute__ ((aligned (32))) = {LANC_H,LANC_L,LANC_L,LANC_H,LANC_H,LANC_H,LANC_L,LANC_L}; // Tele +uint8_t zoomOut[MY_BUF_SIZE] __attribute__ ((aligned (32))) = {LANC_H,LANC_H,LANC_L,LANC_H,LANC_H,LANC_H,LANC_L,LANC_L}; // Wide -uint32_t *normalCmdAddr = (uint32_t*)normalCommand; -uint32_t *startStopAddr = (uint32_t*)startStop; +uint32_t *normalCmdAddr = (uint32_t*)specialCommand; +uint32_t *startStopAddr = (uint32_t*)zoomOut; uint8_t firstInt = 1; uint8_t flag = 0; -uint8_t state = 0; /* 0 -> Send command type, 1-> send command */ +uint8_t state = 0; /* 1 -> Send command type, 0 -> send command */ InterruptIn button(LANC_PIN); -Timer lancTimer; Timer frameTimer; void sendCommand(void){ - static int timePassed_ms = 0; static int lastIntTime_us = 0; /* @@ -90,14 +85,11 @@ int main(void){ - led = 1; alive = 0; NRF_I2S->CONFIG.RXEN = 0; // Disable reception NRF_I2S->CONFIG.MCKEN = 1; // Enable MCK generator - - //NRF_I2S->CONFIG.MCKFREQ = 0x04100000; // DIV 63 - //NRF_I2S->CONFIG.RATIO = 0; // Ratio = 32x + NRF_I2S->CONFIG.MCKFREQ = 0x10000000; // DIV 31 NRF_I2S->CONFIG.RATIO = 0; // Ratio = 32x @@ -106,9 +98,6 @@ NRF_I2S->CONFIG.FORMAT = 0; // Format = I2S NRF_I2S->CONFIG.CHANNELS = 0; // Use stereo - - - // In debug mode NRF_I2S->PSEL.LRCK = 27; // LRCK routed to pin 26 NRF_I2S->PSEL.SDOUT = LANC_COMMAND_PIN; // SDOUT routed to pin 28 NRF_I2S->PSEL.SCK = 30; // SCK routed to pin 30 @@ -118,24 +107,9 @@ NRF_I2S->TXD.PTR = (uint32_t)normalCmdAddr; NRF_I2S->RXTXD.MAXCNT = MY_BUF_SIZE/4; // Div with 4 cuz that's number of 32 bit words - - - //NRF_I2S->ENABLE = 1; - //NRF_I2S->TASKS_START = 1; - button.fall(sendCommand); while(1){ - if(flag){ - /* - if(state == 1){ - NRF_I2S->TXD.PTR = (uint32_t)startStopAddr; - } - else if(state == 2){ - NRF_I2S->TXD.PTR = (uint32_t)normalCmdAddr; - } - */ - - led = 0; + if(flag){ while(!NRF_I2S->EVENTS_TXPTRUPD); // Wait for the data to be send NRF_I2S->EVENTS_TXPTRUPD = 0; while(!NRF_I2S->EVENTS_TXPTRUPD); // Wait for the data to be send @@ -145,7 +119,6 @@ while(!NRF_I2S->EVENTS_STOPPED); NRF_I2S->ENABLE = 0; flag = 0; - led = 1; __enable_irq(); } }