mai2: update all LED boards to use two boards

This commit is contained in:
2025-03-02 00:01:45 +01:00
parent a1611afffc
commit 4cb76dd1ee
43 changed files with 273 additions and 265 deletions

View File

@ -103,19 +103,30 @@ HRESULT led15070_hook_init(
io_led_set_fet_output_t _led_set_fet_output,
io_led_dc_update_t _led_dc_update,
io_led_gs_update_t _led_gs_update,
unsigned int first_port,
unsigned int num_boards)
unsigned int port_no[2])
{
unsigned int num_boards = 0;
assert(cfg != NULL);
assert(_led_init != NULL);
if (!cfg->enable) {
return S_FALSE;
}
if (cfg->port_no != 0) {
first_port = cfg->port_no;
for (int i = 0; i < led15070_nboards; i++)
{
if (cfg->port_no[i] != 0) {
port_no[i] = cfg->port_no[i];
}
if (port_no[i] != 0) {
num_boards++;
}
}
assert(num_boards != 0);
led_init = _led_init;
led_set_fet_output = _led_set_fet_output;
led_dc_update = _led_dc_update;
@ -131,10 +142,7 @@ HRESULT led15070_hook_init(
InitializeCriticalSection(&v->lock);
// TODO: IMPROVE!
first_port = i == 1 ? first_port + 2 : first_port;
uart_init(&v->boarduart, first_port);
uart_init(&v->boarduart, port_no[i]);
v->boarduart.baud.BaudRate = 115200;
v->boarduart.written.bytes = v->written_bytes;
v->boarduart.written.nbytes = sizeof(v->written_bytes);
@ -681,7 +689,7 @@ static HRESULT led15070_req_set_fet_output(int board, const struct led15070_req_
led15070_per_board_vars[board].fet[2] = req->payload[2]; // B or FET2 intensity
if (led_set_fet_output)
led_set_fet_output((const uint8_t*)led15070_per_board_vars[board].fet);
led_set_fet_output(board, (const uint8_t*)led15070_per_board_vars[board].fet);
if (!led15070_per_board_vars[board].enable_response)
return S_OK;
@ -737,7 +745,7 @@ static HRESULT led15070_req_dc_update(int board, const struct led15070_req_any *
#endif
if (led_dc_update)
led_dc_update((const uint8_t*)led15070_per_board_vars[board].dc);
led_dc_update(board, (const uint8_t*)led15070_per_board_vars[board].dc);
if (!led15070_per_board_vars[board].enable_response)
return S_OK;
@ -764,7 +772,7 @@ static HRESULT led15070_req_gs_update(int board, const struct led15070_req_any *
#endif
if (led_gs_update)
led_gs_update((const uint8_t*)led15070_per_board_vars[board].gs);
led_gs_update(board, (const uint8_t*)led15070_per_board_vars[board].gs);
if (!led15070_per_board_vars[board].enable_response)
return S_OK;

View File

@ -7,7 +7,7 @@
struct led15070_config {
bool enable;
unsigned int port_no;
unsigned int port_no[2];
char board_number[8];
uint8_t fw_ver;
uint16_t fw_sum;
@ -15,9 +15,9 @@ struct led15070_config {
};
typedef HRESULT (*io_led_init_t)(void);
typedef void (*io_led_set_fet_output_t)(const uint8_t *rgb);
typedef void (*io_led_dc_update_t)(const uint8_t *rgb);
typedef void (*io_led_gs_update_t)(const uint8_t *rgb);
typedef void (*io_led_set_fet_output_t)(uint8_t board, const uint8_t *rgb);
typedef void (*io_led_dc_update_t)(uint8_t board, const uint8_t *rgb);
typedef void (*io_led_gs_update_t)(uint8_t board, const uint8_t *rgb);
HRESULT led15070_hook_init(
const struct led15070_config *cfg,
@ -25,5 +25,4 @@ HRESULT led15070_hook_init(
io_led_set_fet_output_t _led_set_fet_output,
io_led_dc_update_t _led_dc_update,
io_led_gs_update_t _led_gs_update,
unsigned int first_port,
unsigned int num_boards);
unsigned int port_no[2]);

View File

@ -107,9 +107,13 @@ static uint8_t led15093_host_adr = 1;
static io_led_init_t led_init;
static io_led_set_leds_t set_leds;
HRESULT led15093_hook_init(const struct led15093_config *cfg, io_led_init_t _led_init,
io_led_set_leds_t _set_leds, unsigned int first_port, unsigned int num_boards, uint8_t board_adr, uint8_t host_adr)
HRESULT led15093_hook_init(
const struct led15093_config *cfg,
io_led_init_t _led_init,
io_led_set_leds_t _set_leds,
unsigned int port_no[2])
{
unsigned int num_boards = 0;
assert(cfg != NULL);
assert(_led_init != NULL);
@ -119,14 +123,24 @@ HRESULT led15093_hook_init(const struct led15093_config *cfg, io_led_init_t _led
return S_FALSE;
}
if (cfg->port_no != 0) {
first_port = cfg->port_no;
for (int i = 0; i < led15093_nboards; i++)
{
if (cfg->port_no[i] != 0) {
port_no[i] = cfg->port_no[i];
}
if (port_no[i] != 0) {
num_boards++;
}
}
assert(num_boards != 0);
led15093_board_adr = num_boards;
led15093_host_adr = num_boards == 2 ? 1 : 2;
led_init = _led_init;
set_leds = _set_leds;
led15093_board_adr = board_adr;
led15093_host_adr = host_adr;
memcpy(led15093_board_num, cfg->board_number, sizeof(led15093_board_num));
memcpy(led15093_chip_num, cfg->chip_number, sizeof(led15093_chip_num));
@ -140,7 +154,7 @@ HRESULT led15093_hook_init(const struct led15093_config *cfg, io_led_init_t _led
InitializeCriticalSection(&vb->lock);
uart_init(&vb->boarduart, first_port + i);
uart_init(&vb->boarduart, port_no[i]);
if (cfg->high_baudrate) {
vb->boarduart.baud.BaudRate = 460800;
} else {
@ -209,7 +223,6 @@ static HRESULT led15093_handle_irp_locked(int board, struct irp *irp)
_led15093_per_board_vars *v = &led15093_per_board_vars[board];
struct uart *boarduart = &led15093_per_board_vars[board].boarduart;
/*
if (irp->op == IRP_OP_OPEN) {
// Unfortunately the LED board UART gets opened and closed repeatedly
@ -236,30 +249,6 @@ static HRESULT led15093_handle_irp_locked(int board, struct irp *irp)
}
}
}
*/
if (irp->op == IRP_OP_OPEN) {
dprintf("LED 15093: Starting backend DLL\n");
// int res = led_init();
hr = led_init();
/*
if (res != 0) {
dprintf("LED 15093: Backend error, LED board disconnected: "
"%d\n",
res);
return E_FAIL;
}
*/
if (FAILED(hr)) {
dprintf("LED 15093: Backend error, LED board disconnected: "
"%x\n",
(int) hr);
return hr;
}
}
hr = uart_handle_irp(boarduart, irp);
@ -688,16 +677,6 @@ static HRESULT led15093_req_set_imm_led(int board, const struct led15093_req_set
return E_INVALIDARG;
}
/*
if (board == 0) {
dprintf("board %d: red: %d, green: %d, blue: %d\n", board, req->data[0x96], req->data[0x97], req->data[0x98]);
}
else if (board == 1)
{
dprintf("board %d: red: %d, green: %d, blue: %d\n", board, req->data[0xb4], req->data[0xb5], req->data[0xb6]);
}
*/
// Return the current LED data, remove const qualifier
set_leds(board, (uint8_t *) req->data);

View File

@ -8,7 +8,7 @@
struct led15093_config {
bool enable;
bool high_baudrate;
unsigned int port_no;
unsigned int port_no[2];
char board_number[8];
char chip_number[5];
char boot_chip_number[5];
@ -20,5 +20,5 @@ typedef HRESULT (*io_led_init_t)(void);
typedef void (*io_led_set_leds_t)(uint8_t board, uint8_t *rgb);
HRESULT led15093_hook_init(const struct led15093_config *cfg, io_led_init_t _led_init,
io_led_set_leds_t _set_leds, unsigned int first_port, unsigned int num_boards, uint8_t board_adr, uint8_t host_adr);
io_led_set_leds_t _set_leds, unsigned int port_no[2]);