Jurica Resetar / Mbed OS acn52832_LANC_BLE

Dependencies:   aconno_LANC aconno_bsp aconno_SEGGER_RTT

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers aconno_i2s.cpp Source File

aconno_i2s.cpp

00001 /*
00002  * Made by Jurica Resetar @ aconno
00003  * jurica_resetar@yahoo.com
00004  * More info @ aconno.de
00005  *
00006  * All rights reserved
00007  *
00008  */
00009  
00010 #include "mbed.h"
00011 #include "aconno_i2s.h"
00012 
00013 aconno_i2s::aconno_i2s(){
00014     // Constructor
00015 }
00016 
00017 void aconno_i2s::init(uint8_t dataOutPin, uint8_t LrckPin, uint8_t SckPin, uint16_t bufferSize_B, uint8_t *dataPointer){
00018     NRF_I2S->CONFIG.RXEN = 0;       // Disable reception
00019     NRF_I2S->CONFIG.MCKEN = 1;      // Enable MCK generator
00020     
00021     NRF_I2S->CONFIG.MCKFREQ = 0x10000000;   // DIV 31
00022     NRF_I2S->CONFIG.RATIO = 0;              // Ratio = 32x
00023     
00024     NRF_I2S->CONFIG.SWIDTH = 0;             // Sample width = 8 bit
00025     NRF_I2S->CONFIG.ALIGN = 0;              // Alignment = Right
00026     NRF_I2S->CONFIG.FORMAT = 0;             // Format = I2S
00027     NRF_I2S->CONFIG.CHANNELS = 0;           // Use stereo
00028     
00029     NRF_I2S->PSEL.LRCK = LrckPin;           // LRCK routed to pin 26
00030     NRF_I2S->PSEL.SDOUT = dataOutPin;          // SDOUT routed to pin 28
00031     NRF_I2S->PSEL.SCK = SckPin;             // SCK routed to pin 30
00032     NRF_I2S->PSEL.MCK = 0x80000000;         // MCK disconnected
00033     NRF_I2S->PSEL.SDIN = 0x80000000;        // SDIN disconnected
00034     
00035     NRF_I2S->TXD.PTR = (uint32_t)dataPointer;
00036     NRF_I2S->RXTXD.MAXCNT = bufferSize_B/4;  // Div with 4 cuz that's number of 32 bit words
00037 }
00038 
00039 void aconno_i2s::sendData(){
00040     /* 
00041      *  I2S bits go from MSB to LSB on the bus
00042      */
00043      
00044     NRF_I2S->EVENTS_TXPTRUPD = 0;
00045     NRF_I2S->ENABLE = 1;
00046     NRF_I2S->TASKS_START = 1;    
00047     
00048     while(!NRF_I2S->EVENTS_TXPTRUPD);    // Wait for the data to be send
00049     NRF_I2S->EVENTS_TXPTRUPD = 0;
00050     while(!NRF_I2S->EVENTS_TXPTRUPD);    // Wait for the data to be send
00051     NRF_I2S->EVENTS_TXPTRUPD = 0; 
00052     NRF_I2S->TASKS_STOP = 1;
00053     while(!NRF_I2S->EVENTS_STOPPED);
00054     NRF_I2S->ENABLE = 0;
00055 }
00056  
00057