summaryrefslogtreecommitdiff
path: root/Core/Inc/cs4272.h
blob: 4e222638247499f2aa96590e4cd593d8fb5fae2a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
 * cs4272.h
 *
 *  Created on: Aug 16, 2026
 *      Author: ozpv
 */

#ifndef INC_CS4272_H_
#define INC_CS4272_H_

#include <stdint.h>

/* cs4272k-czzr 7. REGISTER QUICK REFERENCE */
#define MODE_CONTROL_1 0x01
#define DAC_CONTROL 0x02
#define DAC_VOLUME_AND_MIXING_CONTROL 0x03
#define DAC_CH_A_VOLUME_CONTROL 0x04
#define DAC_CH_B_VOLUME_CONTROL 0x05
#define ADC_CONTROL 0x06
#define MODE_CONTROL_2 0x07
#define CHIP_ID 0x08

#define CS4272_CHIP_ID 0x0

/* set by ad0 ncs pin */
#define CS4272_I2C_ADDR (0b0010000 << 1)

#define SAMPLE_RATE 48000
#define BUFFER_SIZE 1024

typedef enum Channel {
    LEFT = 0,
    RIGHT = 1,
    MONO = 0,
} Channel;

extern int32_t rx_buffer[BUFFER_SIZE];
extern int32_t tx_buffer[BUFFER_SIZE];

extern const uint8_t CS4272_CONFIG[7];

uint8_t CS4272_Init(void);

static inline __attribute__((always_inline)) float int24_t_to_f32(const int32_t in) {
    return ((float)(in << 8)) / ((float)INT32_MAX);
}

static inline __attribute__((always_inline)) int32_t f32_to_int24_t(const float in) {
    return ((int32_t)(in * ((float)INT32_MAX))) >> 8;
}

#endif /* INC_CS4272_H_ */