Skip to content

Instantly share code, notes, and snippets.

@hktechn0
Created September 15, 2014 07:30
Show Gist options
  • Save hktechn0/c84cff5ea2b785234ab8 to your computer and use it in GitHub Desktop.
Save hktechn0/c84cff5ea2b785234ab8 to your computer and use it in GitHub Desktop.
Micro Python cs43l22 driver
import pyb
from pyb import I2C
from pyb import Pin
DEVICE_ADDR = 0x4a
BEEPTONE_ADDR = 0x1e
class CS43L22:
def __init__(self):
self.reset = Pin(Pin.board.PD4, Pin.OUT_PP)
self.reset.low()
pyb.delay(100)
self.reset.high()
pyb.delay(1000)
self.i2c = I2C(1, I2C.MASTER, baudrate=100000)
def init(self):
print([hex(i) for i in self.i2c.scan()])
if self.i2c.is_ready(DEVICE_ADDR):
print("ready")
self.i2c.mem_write(0x99, DEVICE_ADDR, 0x00)
self.i2c.mem_write(0x80, DEVICE_ADDR, 0x47)
self.i2c.mem_write(0x80, DEVICE_ADDR, 0x32)
self.i2c.mem_write(0x00, DEVICE_ADDR, 0x32)
self.i2c.mem_write(0x00, DEVICE_ADDR, 0x00)
self.i2c.mem_write(0x9e, DEVICE_ADDR, 0x02)
pyb.delay(1000)
# Volume
self.i2c.mem_write(0x18, DEVICE_ADDR, 0x20)
self.i2c.mem_write(0x18, DEVICE_ADDR, 0x21)
self.i2c.mem_write(0x18, DEVICE_ADDR, 0x1a)
self.i2c.mem_write(0x18, DEVICE_ADDR, 0x1b)
self.i2c.mem_write(0x0f, DEVICE_ADDR, 0x1c)
self.i2c.mem_write(0x06, DEVICE_ADDR, 0x1d)
self.i2c.mem_write(0xc0, DEVICE_ADDR, BEEPTONE_ADDR)
audio = CS43L22()
pyb.delay(1000)
audio.init()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment