diff options
author | Jon Bergli Heier <snakebite@jvnv.net> | 2012-09-29 15:43:21 +0200 |
---|---|---|
committer | Jon Bergli Heier <snakebite@jvnv.net> | 2012-09-29 15:43:21 +0200 |
commit | b0f007de6a8c9762026f015baade66747fb849bd (patch) | |
tree | f51e987d4eb7f79b542fdb0677101dc9c50f2698 | |
parent | 2c581cb537b132c66219d7c920969773dc210db5 (diff) |
Moved audio initialization to the DAC class.
-rw-r--r-- | main.cpp | 43 |
1 files changed, 36 insertions, 7 deletions
@@ -82,6 +82,41 @@ auto conf_desc = configuration_desc(2, 1, 0, 0xc0, 0, ) ); +class DAC { + Pin& reset; + I2C& i2c; + uint8_t volume; + + public: + DAC(Pin& _reset, I2C& _i2c) : reset(_reset), i2c(_i2c) { + reset.set_mode(Pin::Output); + reset.off(); + } + + void init() { + // Configure CS43L22. + reset.on(); + + i2c.write_reg(0x4a, 0x02, 0x9e); + i2c.write_reg(0x4a, 0x06, (0 << 7) | (1 << 6) | (0 << 4) | (1 << 2) | (3 << 0)); + set_volume(-0x40); + //i2c.write_reg(0x4a, 0x1a, 0); + //i2c.write_reg(0x4a, 0x1b, 0); + //i2c.write_reg(0x4a, 0x1a, -0x40 & 0x7f); + //i2c.write_reg(0x4a, 0x1b, -0x40 & 0x7f); + } + uint8_t get_volume() { + return volume; + } + void set_volume(uint8_t v) { + volume = v; + i2c.write_reg(0x4a, 0x1a, volume & 0x7f); + i2c.write_reg(0x4a, 0x1b, volume & 0x7f); + } +}; + +DAC dac(dac_nreset, I2C1); + desc_t dev_desc_p = {sizeof(dev_desc), (void*)&dev_desc}; desc_t conf_desc_p = {sizeof(conf_desc), (void*)&conf_desc}; @@ -163,7 +198,6 @@ class USB_Audio : public USB_class_driver { USB_Audio usb_audio(usb); - int main() { // Initialize system timer. STK.LOAD = 168000000 / 8 / 1000; // 1000 Hz. @@ -206,12 +240,7 @@ int main() { // Initialize I2C. I2C1.enable(i2c_scl, i2c_sda); - // Configure CS43L22. - dac_nreset.set_mode(Pin::Output); - dac_nreset.on(); - - I2C1.write_reg(0x4a, 0x02, 0x9e); - I2C1.write_reg(0x4a, 0x06, (0 << 7) | (1 << 6) | (0 << 4) | (1 << 2) | (3 << 0)); + dac.init(); // Initialize USB. usb_vbus.set_mode(Pin::Input); |