77 lines
1.5 KiB
C
77 lines
1.5 KiB
C
#pragma once
|
|
|
|
#include <stddef.h>
|
|
#include <stdint.h>
|
|
|
|
// ----------------------
|
|
// I2C
|
|
// ----------------------
|
|
#define ES8311_I2C_ADDR 0x18
|
|
|
|
// ----------------------
|
|
// System
|
|
// ----------------------
|
|
#define ES8311_RESET 0x00
|
|
#define ES8311_CLK_MANAGE 0x01
|
|
#define ES8311_CLK_DIV 0x02
|
|
|
|
// ----------------------
|
|
// Power
|
|
// ----------------------
|
|
#define ES8311_PWR_UP_DOWN 0x0C
|
|
#define ES8311_PWR_ANALOG 0x0D
|
|
|
|
#define ES8311_PWR_DAC_EN (1 << 0)
|
|
#define ES8311_PWR_ADC_EN (1 << 1)
|
|
|
|
// ----------------------
|
|
// Audio format
|
|
// ----------------------
|
|
#define ES8311_SER_FMT 0x10
|
|
|
|
#define ES8311_FMT_I2S 0x18
|
|
#define ES8311_FMT_LEFT 0x10
|
|
|
|
#define ES8311_WORD_LEN_16 0x10
|
|
#define ES8311_WORD_LEN_24 0x20
|
|
|
|
// ----------------------
|
|
// ADC
|
|
// ----------------------
|
|
#define ES8311_ADC_CTRL1 0x14
|
|
#define ES8311_ADC_CTRL2 0x15
|
|
|
|
#define ES8311_ADC_VOL 0x16
|
|
|
|
// ----------------------
|
|
// DAC
|
|
// ----------------------
|
|
#define ES8311_DAC_CTRL1 0x17
|
|
#define ES8311_DAC_CTRL2 0x18
|
|
|
|
#define ES8311_DAC_VOL_L 0x33
|
|
#define ES8311_DAC_VOL_R 0x34
|
|
|
|
// ----------------------
|
|
// Output
|
|
// ----------------------
|
|
#define ES8311_HP_CTRL 0x31
|
|
#define ES8311_SPK_CTRL 0x32
|
|
|
|
// ----------------------
|
|
// Common
|
|
// ----------------------
|
|
#define ES8311_RESET_CMD 0x1F
|
|
#define ES8311_ALL_ON 0xFF
|
|
|
|
void es8311_init(void);
|
|
|
|
void es8311_set_dac_volume(uint8_t vol);
|
|
void es8311_set_adc_volume(uint8_t vol);
|
|
|
|
int audio_write(const int16_t *samples, size_t count);
|
|
|
|
int audio_read(int16_t *samples, size_t count);
|
|
|
|
void audio_beep(void);
|