Sony's LANC camera control protocol project.

Dependencies:   aconno_LANC aconno_bsp aconno_SEGGER_RTT

Committer:
jurica238814
Date:
Fri Oct 13 16:34:29 2017 +0000
Revision:
0:d616ca59aad8
Child:
1:3e3dded8192f
I2S works. Starts in button interrupt handler.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jurica238814 0:d616ca59aad8 1 /*
jurica238814 0:d616ca59aad8 2 * Example to demonstrate usage of the nrf52's I2S interface
jurica238814 0:d616ca59aad8 3 *
jurica238814 0:d616ca59aad8 4 * Made by Jurica Resetar @ aconno
jurica238814 0:d616ca59aad8 5 * jurica_resetar@yahoo.com
jurica238814 0:d616ca59aad8 6 * More info @ aconno.de
jurica238814 0:d616ca59aad8 7 *
jurica238814 0:d616ca59aad8 8 * All rights reserved
jurica238814 0:d616ca59aad8 9 *
jurica238814 0:d616ca59aad8 10 */
jurica238814 0:d616ca59aad8 11
jurica238814 0:d616ca59aad8 12 #include "mbed.h"
jurica238814 0:d616ca59aad8 13 #include "acd52832_bsp.h"
jurica238814 0:d616ca59aad8 14
jurica238814 0:d616ca59aad8 15 #define MY_BUF_SIZE 3*8*2
jurica238814 0:d616ca59aad8 16 #define LANC_H 0xFFFF, 0xFFFF, 0xFFFF
jurica238814 0:d616ca59aad8 17 #define LANC_L 0x0000, 0x0000, 0x0000
jurica238814 0:d616ca59aad8 18
jurica238814 0:d616ca59aad8 19 /*
jurica238814 0:d616ca59aad8 20 * Bitovi na I2S bus idu od MSBa do LSBa
jurica238814 0:d616ca59aad8 21 */
jurica238814 0:d616ca59aad8 22
jurica238814 0:d616ca59aad8 23 #define REC_CMD_1 (0x18) // 0xE7 or 0x18
jurica238814 0:d616ca59aad8 24 #define REC_CMD_2 (0x33) // 0xCC or 0x33
jurica238814 0:d616ca59aad8 25
jurica238814 0:d616ca59aad8 26 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};
jurica238814 0:d616ca59aad8 27 uint8_t my_rx_buf[10] = {};
jurica238814 0:d616ca59aad8 28 uint8_t flag = 0;
jurica238814 0:d616ca59aad8 29 InterruptIn button(PIN_BUTTON);
jurica238814 0:d616ca59aad8 30
jurica238814 0:d616ca59aad8 31 void sendCommand(void){
jurica238814 0:d616ca59aad8 32 NRF_I2S->TASKS_START = 1;
jurica238814 0:d616ca59aad8 33 while(!NRF_I2S->EVENTS_TXPTRUPD); // Wait for the data to be send
jurica238814 0:d616ca59aad8 34 NRF_I2S->EVENTS_TXPTRUPD = 0;
jurica238814 0:d616ca59aad8 35 flag = 1;
jurica238814 0:d616ca59aad8 36 }
jurica238814 0:d616ca59aad8 37
jurica238814 0:d616ca59aad8 38 int main(void){
jurica238814 0:d616ca59aad8 39 NRF_I2S->CONFIG.RXEN = 0; // Disable reception
jurica238814 0:d616ca59aad8 40 NRF_I2S->CONFIG.TXEN = 1; // Enable transmission
jurica238814 0:d616ca59aad8 41 NRF_I2S->CONFIG.MCKEN = 1; // Enable MCK generator
jurica238814 0:d616ca59aad8 42
jurica238814 0:d616ca59aad8 43 //NRF_I2S->CONFIG.MCKFREQ = 0x04100000; // DIV 63
jurica238814 0:d616ca59aad8 44 //NRF_I2S->CONFIG.RATIO = 0; // Ratio = 32x
jurica238814 0:d616ca59aad8 45 NRF_I2S->CONFIG.MCKFREQ = 0x08200000; // DIV 31
jurica238814 0:d616ca59aad8 46 NRF_I2S->CONFIG.RATIO = 2; // Ratio = 64x
jurica238814 0:d616ca59aad8 47
jurica238814 0:d616ca59aad8 48 NRF_I2S->CONFIG.SWIDTH = 1; // Sample width = 16 bit
jurica238814 0:d616ca59aad8 49 NRF_I2S->CONFIG.ALIGN = 1; // Alignment = Right
jurica238814 0:d616ca59aad8 50 NRF_I2S->CONFIG.FORMAT = 0; // Format = I2S
jurica238814 0:d616ca59aad8 51 NRF_I2S->CONFIG.CHANNELS = 0; // Use stereo
jurica238814 0:d616ca59aad8 52
jurica238814 0:d616ca59aad8 53
jurica238814 0:d616ca59aad8 54 // In debug mode
jurica238814 0:d616ca59aad8 55 NRF_I2S->PSEL.LRCK = 26; // LRCK routed to pin 26
jurica238814 0:d616ca59aad8 56 NRF_I2S->PSEL.SDOUT = 28; // SDOUT routed to pin 28
jurica238814 0:d616ca59aad8 57 NRF_I2S->PSEL.SCK = 30; // SCK routed to pin 30
jurica238814 0:d616ca59aad8 58 NRF_I2S->PSEL.MCK = 0x80000000; // MCK disconnected
jurica238814 0:d616ca59aad8 59 NRF_I2S->PSEL.SDIN = 0x80000000; // SDIN disconnected
jurica238814 0:d616ca59aad8 60
jurica238814 0:d616ca59aad8 61 NRF_I2S->TXD.PTR = (uint32_t)my_tx_buf;
jurica238814 0:d616ca59aad8 62 NRF_I2S->RXD.PTR = (uint32_t)my_rx_buf;
jurica238814 0:d616ca59aad8 63 NRF_I2S->RXTXD.MAXCNT = MY_BUF_SIZE/2; // Ajde ustanovi zašto pobogu /2
jurica238814 0:d616ca59aad8 64
jurica238814 0:d616ca59aad8 65 NRF_I2S->ENABLE = 1;
jurica238814 0:d616ca59aad8 66 //NRF_I2S->TASKS_START = 1;
jurica238814 0:d616ca59aad8 67
jurica238814 0:d616ca59aad8 68 button.rise(sendCommand);
jurica238814 0:d616ca59aad8 69 while(1){
jurica238814 0:d616ca59aad8 70 if(flag){
jurica238814 0:d616ca59aad8 71 wait_ms(50);
jurica238814 0:d616ca59aad8 72 NRF_I2S->TASKS_STOP = 1;
jurica238814 0:d616ca59aad8 73 while(!NRF_I2S->EVENTS_STOPPED);
jurica238814 0:d616ca59aad8 74 NRF_I2S->EVENTS_STOPPED = 0;
jurica238814 0:d616ca59aad8 75 flag = 0;
jurica238814 0:d616ca59aad8 76 }
jurica238814 0:d616ca59aad8 77 }
jurica238814 0:d616ca59aad8 78 }
jurica238814 0:d616ca59aad8 79
jurica238814 0:d616ca59aad8 80