summaryrefslogtreecommitdiff
path: root/firmware/src/p2m.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/src/p2m.c')
-rw-r--r--firmware/src/p2m.c93
1 files changed, 83 insertions, 10 deletions
diff --git a/firmware/src/p2m.c b/firmware/src/p2m.c
index d44a01c..aa5250d 100644
--- a/firmware/src/p2m.c
+++ b/firmware/src/p2m.c
@@ -9,8 +9,8 @@
//#define IRQ_BLINKY
//#define BLINKY
//#define BLINKY
-//#define WM8523
-#define SPI
+#define WM8523
+//#define SPI
#ifdef DMA
@@ -136,7 +136,8 @@ int main (void)
#ifdef WM8523
-#include <cli.h>
+#include <ssp.h>
+#include <GPIO.h>
#include <wm8523.h>
#include <led.h>
@@ -147,20 +148,92 @@ int main (void)
LED_Init();
- _delay(1 << 22);
+ uint8_t portnum = 0;
+
+ wm8523_init(portnum, WM8523_FS_44K1);
+
+ if(wm8523_get_chip_id(portnum) != WM8532_CHIP_ID) goto fail;
- WM8523_init();
+ wm8523_reset_registers(portnum);
- _delay(1 << 22);
+ wm8523_power_mode_t pwr = WM8523_PWR_POWER_UP_TO_UNMUTE;
+ wm8523_set_power_mode(portnum, pwr);
- WM8523_configure();
+ wm8523_aif_ctrl1_t ctl1;
+ ctl1.fmt = WM8523_FMT_I2S;
+ ctl1.wlen = WM8523_WLEN_32;
+ ctl1.invctl = WM8523_INVCTL_SLAVE_RISING;
+ ctl1.lrclkinvctl = WM8523_LRCLKINVCTL_SLAVE_NORMAL;
+ ctl1.modesel = WM8523_MODESEL_SLAVE;
+ ctl1.deemp = WM8523_DEEMPH_ENABLED;
+ wm8523_set_aif_ctrl1(portnum, ctl1);
+
+ wm8523_aif_ctrl2_t ctl2;
+ ctl2.clkratio = WM8523_CLKRATIO_AUTO;
+ ctl2.clkdiv = WM8523_CLKDIV_MCLK_4;
+ ctl2.mix = WM8523_MIX_STEREO;
+ wm8523_set_aif_ctrl2(portnum, ctl2);
+
+ wm8523_dac_ctrl3_t ctl3;
+ ctl3.downramp = WM8523_VOL_DOWN_INSTANT;
+ ctl3.upramp = WM8523_VOL_UP_INSTANT;
+ ctl3.lmute = WM8523_DACL_UNMUTE;
+ ctl3.rmute = WM8523_DACR_UNMUTE;
+ ctl3.dac_zc = WM8523_ZERO_CROSSING_DISABLED;
+ wm8523_set_dac_ctrl3(portnum, ctl3);
+
+ /*
+ // Init SPI
+ GPIOSetDir(0, 16, 1);
+ GPIOSetValue(0, 16, 1);
+
+ SSP0Init();
+
+ uint8_t src_addr[16]; //16 byte Write buffer
+ uint8_t portnum = 0;
+
+ // Set bitwidth to 16
+ // Set interface format to I2S
+ GPIOSetValue(0, 16, 0);
+ src_addr[0] = 0x0 << 7 | 0x3; // write bit (0) | register 3
+ src_addr[1] =
+ 0x2 << 0 | // Set I2S mode
+ 0x0 << 2 | // Reserved
+ 0x0 << 3; // Set 16 bit
+ // The rest are 0 as default which is correct
+
+ SSPSend(portnum, (uint8_t *)src_addr, 2);
+ GPIOSetValue(0, 16, 1);
+
+ _delay(1 << 5);
+
+ // Power up and unmute
+ GPIOSetValue(0, 16, 0);
+ src_addr[0] = 0x0 << 7 | 0x2; // write bit (0) | register 2 (power register)
+ src_addr[1] = 0x2; // Set power mode: "power up and unmute"
+ SSPSend(portnum, (uint8_t *)src_addr, 2);
+ GPIOSetValue(0, 16, 1);
+ */
+
+
+ //wm8523_init();
+
+ // WM8523_configure();
+
+ //_delay(1 << 5);
+
+ wm8523_tone();
// Indicate that we didn't crash before the end...
- int i = 0;
- while(1) {
+ while(1) { // slow blink
LED_toggle();
_delay(1 << 21);
- i = 1 - i;
+ }
+
+fail:
+ while(1) { // fast blink
+ LED_toggle();
+ _delay(1 << 17);
}
}