Sony's LANC camera control protocol project.
Dependencies: aconno_LANC aconno_bsp aconno_SEGGER_RTT
Diff: main.cpp
- Revision:
- 0:d616ca59aad8
- Child:
- 1:3e3dded8192f
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Fri Oct 13 16:34:29 2017 +0000 @@ -0,0 +1,80 @@ +/* + * Example to demonstrate usage of the nrf52's I2S interface + * + * Made by Jurica Resetar @ aconno + * jurica_resetar@yahoo.com + * More info @ aconno.de + * + * All rights reserved + * + */ + +#include "mbed.h" +#include "acd52832_bsp.h" + +#define MY_BUF_SIZE 3*8*2 +#define LANC_H 0xFFFF, 0xFFFF, 0xFFFF +#define LANC_L 0x0000, 0x0000, 0x0000 + +/* + * Bitovi na I2S bus idu od MSBa do LSBa + */ + +#define REC_CMD_1 (0x18) // 0xE7 or 0x18 +#define REC_CMD_2 (0x33) // 0xCC or 0x33 + +uint16_t my_tx_buf[MY_BUF_SIZE] = {LANC_L,LANC_L,LANC_L,LANC_H, LANC_H,LANC_L,LANC_L,LANC_L, LANC_L,LANC_L,LANC_H,LANC_H,LANC_L,LANC_L,LANC_H,LANC_H}; +uint8_t my_rx_buf[10] = {}; +uint8_t flag = 0; +InterruptIn button(PIN_BUTTON); + +void sendCommand(void){ + NRF_I2S->TASKS_START = 1; + while(!NRF_I2S->EVENTS_TXPTRUPD); // Wait for the data to be send + NRF_I2S->EVENTS_TXPTRUPD = 0; + flag = 1; +} + +int main(void){ + NRF_I2S->CONFIG.RXEN = 0; // Disable reception + NRF_I2S->CONFIG.TXEN = 1; // Enable transmission + 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 = 0x08200000; // DIV 31 + NRF_I2S->CONFIG.RATIO = 2; // Ratio = 64x + + NRF_I2S->CONFIG.SWIDTH = 1; // Sample width = 16 bit + NRF_I2S->CONFIG.ALIGN = 1; // Alignment = Right + NRF_I2S->CONFIG.FORMAT = 0; // Format = I2S + NRF_I2S->CONFIG.CHANNELS = 0; // Use stereo + + + // In debug mode + NRF_I2S->PSEL.LRCK = 26; // LRCK routed to pin 26 + NRF_I2S->PSEL.SDOUT = 28; // SDOUT routed to pin 28 + NRF_I2S->PSEL.SCK = 30; // SCK routed to pin 30 + NRF_I2S->PSEL.MCK = 0x80000000; // MCK disconnected + NRF_I2S->PSEL.SDIN = 0x80000000; // SDIN disconnected + + NRF_I2S->TXD.PTR = (uint32_t)my_tx_buf; + NRF_I2S->RXD.PTR = (uint32_t)my_rx_buf; + NRF_I2S->RXTXD.MAXCNT = MY_BUF_SIZE/2; // Ajde ustanovi zašto pobogu /2 + + NRF_I2S->ENABLE = 1; + //NRF_I2S->TASKS_START = 1; + + button.rise(sendCommand); + while(1){ + if(flag){ + wait_ms(50); + NRF_I2S->TASKS_STOP = 1; + while(!NRF_I2S->EVENTS_STOPPED); + NRF_I2S->EVENTS_STOPPED = 0; + flag = 0; + } + } +} + +