Skip to content

Commit 4e01e6b

Browse files
committed
adafruit-esp32s3-camera: set up backlight at boot & add solarize
the backlight situation will be revisited with the next board prototype, but it's good to prove this can be done. Depends on adafruit/esp32-camera#6 which should be merged before this.
1 parent 2b0f1cd commit 4e01e6b

File tree

2 files changed

+65
-1
lines changed

2 files changed

+65
-1
lines changed

ports/espressif/boards/adafruit_esp32s3_camera/board.c

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
#include "shared-bindings/board/__init__.h"
3636

3737
#include "esp_log.h"
38+
#include "esp_err.h"
39+
#include "driver/i2c.h"
3840

3941
displayio_fourwire_obj_t board_display_obj;
4042

@@ -50,7 +52,69 @@ uint8_t display_init_sequence[] = {
5052
0x29, 0 | DELAY, 5, // _DISPON
5153
};
5254

55+
#define I2C_MASTER_SCL_IO 34
56+
#define I2C_MASTER_SDA_IO 33
57+
#define I2C_MASTER_NUM 0
58+
#define I2C_MASTER_FREQ_HZ 400000
59+
#define I2C_MASTER_TX_BUF_DISABLE 0
60+
#define I2C_MASTER_RX_BUF_DISABLE 0
61+
#define I2C_MASTER_TIMEOUT_MS 1000
62+
#define I2C_WAIT 40 // Timing (in microseconds) for I2C
63+
64+
#define AW9523_ADDR (0x5B)
65+
#define AW9523_REG_SOFTRESET (0x7f)
66+
#define AW9523_REG_OUTPUT0 (0x02)
67+
#define AW9523_REG_CONFIG0 (0x04)
68+
#define AW9523_DEFAULT_OUTPUT (0)
69+
#define AW9523_DEFAULT_CONFIG (0x2)
70+
71+
72+
static void io_expander_backlight_init(void) {
73+
int i2c_num = I2C_MASTER_NUM;
74+
i2c_config_t conf = {
75+
.mode = I2C_MODE_MASTER,
76+
.sda_io_num = I2C_MASTER_SDA_IO,
77+
.scl_io_num = I2C_MASTER_SCL_IO,
78+
.sda_pullup_en = GPIO_PULLUP_ENABLE,
79+
.scl_pullup_en = GPIO_PULLUP_ENABLE,
80+
.master.clk_speed = I2C_MASTER_FREQ_HZ,
81+
};
82+
i2c_param_config(i2c_num, &conf);
83+
i2c_driver_install(i2c_num, conf.mode, I2C_MASTER_RX_BUF_DISABLE, I2C_MASTER_TX_BUF_DISABLE, 0);
84+
i2c_cmd_handle_t cmd = i2c_cmd_link_create();
85+
i2c_master_start(cmd);
86+
i2c_master_write_byte(cmd, AW9523_ADDR << 1 | I2C_MASTER_WRITE, true);
87+
i2c_master_write_byte(cmd, AW9523_REG_SOFTRESET, true);
88+
i2c_master_write_byte(cmd, 0, true);
89+
i2c_master_stop(cmd);
90+
i2c_master_cmd_begin(i2c_num, cmd, 1000 / portTICK_RATE_MS);
91+
i2c_cmd_link_delete(cmd);
92+
93+
cmd = i2c_cmd_link_create();
94+
i2c_master_start(cmd);
95+
i2c_master_write_byte(cmd, AW9523_ADDR << 1 | I2C_MASTER_WRITE, true);
96+
i2c_master_write_byte(cmd, AW9523_REG_CONFIG0, true);
97+
i2c_master_write_byte(cmd, AW9523_DEFAULT_CONFIG >> 8, true);
98+
i2c_master_write_byte(cmd, AW9523_DEFAULT_CONFIG & 0xff, true);
99+
i2c_master_stop(cmd);
100+
i2c_master_cmd_begin(i2c_num, cmd, 1000 / portTICK_RATE_MS);
101+
i2c_cmd_link_delete(cmd);
102+
103+
cmd = i2c_cmd_link_create();
104+
i2c_master_start(cmd);
105+
i2c_master_write_byte(cmd, AW9523_ADDR << 1 | I2C_MASTER_WRITE, true);
106+
i2c_master_write_byte(cmd, AW9523_REG_OUTPUT0, true);
107+
i2c_master_write_byte(cmd, AW9523_DEFAULT_OUTPUT >> 8, true);
108+
i2c_master_write_byte(cmd, AW9523_DEFAULT_OUTPUT & 0xff, true);
109+
i2c_master_stop(cmd);
110+
i2c_master_cmd_begin(i2c_num, cmd, 1000 / portTICK_RATE_MS);
111+
i2c_cmd_link_delete(cmd);
112+
113+
i2c_driver_delete(i2c_num);
114+
}
115+
53116
void board_init(void) {
117+
io_expander_backlight_init();
54118
busio_spi_obj_t *spi = common_hal_board_create_spi(0);
55119
displayio_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus;
56120
bus->base.type = &displayio_fourwire_type;

0 commit comments

Comments
 (0)