Sony's LANC camera control protocol project.

Dependencies:   aconno_LANC aconno_bsp aconno_SEGGER_RTT

Committer:
jurica238814
Date:
Mon Oct 30 12:09:10 2017 +0000
Revision:
1:3e3dded8192f
Parent:
0:d616ca59aad8
Child:
2:b28027b9c099
Alignment problem solved!

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 1:3e3dded8192f 15 #define MY_BUF_SIZE 13*8*2
jurica238814 1:3e3dded8192f 16 #define LANC_H 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF /* 13 B */
jurica238814 1:3e3dded8192f 17 #define LANC_H_L 0xAA, 0xAA, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xAA /* 13 B */
jurica238814 1:3e3dded8192f 18 #define LANC_L 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 /* 13 B */
jurica238814 0:d616ca59aad8 19
jurica238814 0:d616ca59aad8 20 /*
jurica238814 0:d616ca59aad8 21 * Bitovi na I2S bus idu od MSBa do LSBa
jurica238814 0:d616ca59aad8 22 */
jurica238814 0:d616ca59aad8 23
jurica238814 1:3e3dded8192f 24 #define REC_CMD_1 (0xE7) // 0xE7 or 0x18
jurica238814 1:3e3dded8192f 25 #define REC_CMD_2 (0xCC) // 0xCC or 0x33
jurica238814 1:3e3dded8192f 26
jurica238814 1:3e3dded8192f 27 #define LANC_COMMAND_PIN (p26) // Pin connected to Tr to pull lanc bus down/up 2/26
jurica238814 1:3e3dded8192f 28 #define LANC_PIN (p25) // Lanc bus pin (to scan for START/STOP bits) 3/25
jurica238814 0:d616ca59aad8 29
jurica238814 1:3e3dded8192f 30 DigitalOut led(p22);
jurica238814 1:3e3dded8192f 31 //uint8_t my_tx_buf[MY_BUF_SIZE] = {LANC_H,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_L};
jurica238814 1:3e3dded8192f 32 //uint8_t my_tx_buf[MY_BUF_SIZE] = {LANC_H_L,LANC_H_L,LANC_H,LANC_L, LANC_H,LANC_L,LANC_H,LANC_L, LANC_H,LANC_L,LANC_H,LANC_L,LANC_H,LANC_L,LANC_L,LANC_H_L};
jurica238814 1:3e3dded8192f 33 uint8_t my_tx_buf[4] __attribute__ ((aligned (32))) = {0x01, 0x00, 0x00, 0x90};
jurica238814 1:3e3dded8192f 34 uint32_t *adrMyTxBuf = (uint32_t*)my_tx_buf;
jurica238814 1:3e3dded8192f 35
jurica238814 1:3e3dded8192f 36 uint8_t empty_tx_buf[MY_BUF_SIZE] = {LANC_L,LANC_L,LANC_L,LANC_L, LANC_L,LANC_L,LANC_L,LANC_L, LANC_L,LANC_L,LANC_L,LANC_L, LANC_L,LANC_L,LANC_L,LANC_L};
jurica238814 0:d616ca59aad8 37 uint8_t my_rx_buf[10] = {};
jurica238814 0:d616ca59aad8 38 uint8_t flag = 0;
jurica238814 1:3e3dded8192f 39 InterruptIn button(LANC_PIN);
jurica238814 1:3e3dded8192f 40
jurica238814 0:d616ca59aad8 41
jurica238814 1:3e3dded8192f 42 void startLanc(){
jurica238814 1:3e3dded8192f 43 NRF_I2S->EVENTS_TXPTRUPD = 0;
jurica238814 1:3e3dded8192f 44
jurica238814 1:3e3dded8192f 45 NRF_I2S->ENABLE = 1;
jurica238814 1:3e3dded8192f 46 //NRF_I2S->TXD.PTR = (uint32_t)my_tx_buf;
jurica238814 1:3e3dded8192f 47
jurica238814 1:3e3dded8192f 48 NRF_I2S->CONFIG.TXEN = 1; // Enable transmission
jurica238814 0:d616ca59aad8 49 NRF_I2S->TASKS_START = 1;
jurica238814 1:3e3dded8192f 50 //NRF_I2S->TXD.PTR = (uint32_t)my_tx_buf;
jurica238814 0:d616ca59aad8 51 flag = 1;
jurica238814 0:d616ca59aad8 52 }
jurica238814 0:d616ca59aad8 53
jurica238814 1:3e3dded8192f 54 void sendCommand(void){
jurica238814 1:3e3dded8192f 55 //lancTicker.attach_us(startLanc, 10);
jurica238814 1:3e3dded8192f 56 //startLanc();
jurica238814 1:3e3dded8192f 57 NRF_I2S->EVENTS_TXPTRUPD = 0;
jurica238814 1:3e3dded8192f 58 NRF_I2S->ENABLE = 1;
jurica238814 1:3e3dded8192f 59 //NRF_I2S->TXD.PTR = (uint32_t)my_tx_buf;
jurica238814 1:3e3dded8192f 60
jurica238814 1:3e3dded8192f 61 //NRF_I2S->CONFIG.TXEN = 1; // Enable transmission
jurica238814 1:3e3dded8192f 62 NRF_I2S->TASKS_START = 1;
jurica238814 1:3e3dded8192f 63 //NRF_I2S->TXD.PTR = (uint32_t)my_tx_buf;
jurica238814 1:3e3dded8192f 64 flag = 1;
jurica238814 1:3e3dded8192f 65 }
jurica238814 1:3e3dded8192f 66
jurica238814 1:3e3dded8192f 67
jurica238814 1:3e3dded8192f 68
jurica238814 0:d616ca59aad8 69 int main(void){
jurica238814 1:3e3dded8192f 70 led = 1;
jurica238814 1:3e3dded8192f 71
jurica238814 0:d616ca59aad8 72 NRF_I2S->CONFIG.RXEN = 0; // Disable reception
jurica238814 0:d616ca59aad8 73 NRF_I2S->CONFIG.MCKEN = 1; // Enable MCK generator
jurica238814 0:d616ca59aad8 74
jurica238814 0:d616ca59aad8 75 //NRF_I2S->CONFIG.MCKFREQ = 0x04100000; // DIV 63
jurica238814 0:d616ca59aad8 76 //NRF_I2S->CONFIG.RATIO = 0; // Ratio = 32x
jurica238814 1:3e3dded8192f 77 NRF_I2S->CONFIG.MCKFREQ = 0x10000000; // DIV 31
jurica238814 1:3e3dded8192f 78 NRF_I2S->CONFIG.RATIO = 0; // Ratio = 32x
jurica238814 0:d616ca59aad8 79
jurica238814 1:3e3dded8192f 80 NRF_I2S->CONFIG.SWIDTH = 0; // Sample width = 8 bit
jurica238814 1:3e3dded8192f 81 NRF_I2S->CONFIG.ALIGN = 0; // Alignment = Right
jurica238814 0:d616ca59aad8 82 NRF_I2S->CONFIG.FORMAT = 0; // Format = I2S
jurica238814 0:d616ca59aad8 83 NRF_I2S->CONFIG.CHANNELS = 0; // Use stereo
jurica238814 0:d616ca59aad8 84
jurica238814 0:d616ca59aad8 85
jurica238814 1:3e3dded8192f 86
jurica238814 0:d616ca59aad8 87 // In debug mode
jurica238814 1:3e3dded8192f 88 NRF_I2S->PSEL.LRCK = 27; // LRCK routed to pin 26
jurica238814 1:3e3dded8192f 89 NRF_I2S->PSEL.SDOUT = LANC_COMMAND_PIN; // SDOUT routed to pin 28
jurica238814 1:3e3dded8192f 90 NRF_I2S->PSEL.SCK = 30; // SCK routed to pin 30
jurica238814 1:3e3dded8192f 91 NRF_I2S->PSEL.MCK = 0x80000000; // MCK disconnected
jurica238814 1:3e3dded8192f 92 NRF_I2S->PSEL.SDIN = 0x80000000; // SDIN disconnected
jurica238814 0:d616ca59aad8 93
jurica238814 1:3e3dded8192f 94 NRF_I2S->TXD.PTR = (uint32_t)adrMyTxBuf;
jurica238814 1:3e3dded8192f 95 //NRF_I2S->RXTXD.MAXCNT = MY_BUF_SIZE/4; // Div with 4 cuz that's number of 32 bit words
jurica238814 1:3e3dded8192f 96 //NRF_I2S->RXTXD.MAXCNT = 52;
jurica238814 1:3e3dded8192f 97 NRF_I2S->RXTXD.MAXCNT = 1;
jurica238814 1:3e3dded8192f 98
jurica238814 1:3e3dded8192f 99 //NRF_I2S->ENABLE = 1;
jurica238814 0:d616ca59aad8 100 //NRF_I2S->TASKS_START = 1;
jurica238814 0:d616ca59aad8 101
jurica238814 1:3e3dded8192f 102 button.fall(sendCommand);
jurica238814 0:d616ca59aad8 103 while(1){
jurica238814 0:d616ca59aad8 104 if(flag){
jurica238814 1:3e3dded8192f 105 //NRF_I2S->TXD.PTR = (uint32_t)(my_tx_buf);
jurica238814 1:3e3dded8192f 106 led = 0;
jurica238814 1:3e3dded8192f 107 while(!NRF_I2S->EVENTS_TXPTRUPD); // Wait for the data to be send
jurica238814 1:3e3dded8192f 108 NRF_I2S->EVENTS_TXPTRUPD = 0;
jurica238814 1:3e3dded8192f 109 while(!NRF_I2S->EVENTS_TXPTRUPD); // Wait for the data to be send
jurica238814 1:3e3dded8192f 110 NRF_I2S->EVENTS_TXPTRUPD = 0;
jurica238814 1:3e3dded8192f 111 //NRF_I2S->TXD.PTR = (uint32_t)empty_tx_buf;
jurica238814 1:3e3dded8192f 112 //wait_us(2000);
jurica238814 1:3e3dded8192f 113
jurica238814 1:3e3dded8192f 114 //NRF_I2S->TASKS_STOP = 1;
jurica238814 1:3e3dded8192f 115 //while(!NRF_I2S->EVENTS_STOPPED);
jurica238814 1:3e3dded8192f 116 //NRF_I2S->EVENTS_STOPPED = 0;
jurica238814 1:3e3dded8192f 117 NRF_I2S->ENABLE = 0;
jurica238814 1:3e3dded8192f 118 //NRF_I2S->TXD.PTR = (uint32_t)my_tx_buf;
jurica238814 0:d616ca59aad8 119 flag = 0;
jurica238814 1:3e3dded8192f 120 led = 1;
jurica238814 0:d616ca59aad8 121 }
jurica238814 0:d616ca59aad8 122 }
jurica238814 0:d616ca59aad8 123 }
jurica238814 0:d616ca59aad8 124
jurica238814 0:d616ca59aad8 125