aciodrv: refactor to support multiple active drivers (with specified ports)
This commit is contained in:
@@ -14,7 +14,9 @@
|
||||
// in all inputs and outputs (over sub IO) other than 14 keys to not work.
|
||||
static const uint8_t _BIO2DR_BI2A_IIDX_INIT_DATA = 0x2D;
|
||||
|
||||
static bool bio2drv_bi2a_iidx_init_io(uint8_t node_id)
|
||||
static bool bio2drv_bi2a_iidx_init_io(
|
||||
struct aciodrv_device_ctx *device,
|
||||
uint8_t node_id)
|
||||
{
|
||||
struct ac_io_message msg;
|
||||
|
||||
@@ -24,7 +26,9 @@ static bool bio2drv_bi2a_iidx_init_io(uint8_t node_id)
|
||||
msg.cmd.param = _BIO2DR_BI2A_IIDX_INIT_DATA;
|
||||
|
||||
if (!aciodrv_send_and_recv(
|
||||
&msg, offsetof(struct ac_io_message, cmd.raw) + 1)) {
|
||||
device,
|
||||
&msg,
|
||||
offsetof(struct ac_io_message, cmd.raw) + 1)) {
|
||||
log_warning("Init node failed");
|
||||
return 0;
|
||||
}
|
||||
@@ -34,7 +38,9 @@ static bool bio2drv_bi2a_iidx_init_io(uint8_t node_id)
|
||||
return 1;
|
||||
}
|
||||
|
||||
static bool bio2drv_bi2a_iidx_watchdog_start(uint8_t node_id)
|
||||
static bool bio2drv_bi2a_iidx_watchdog_start(
|
||||
struct aciodrv_device_ctx *device,
|
||||
uint8_t node_id)
|
||||
{
|
||||
// exit early and don't actually call watchdog
|
||||
// the watchdog call actually returns different sized packets depending on
|
||||
@@ -54,7 +60,7 @@ static bool bio2drv_bi2a_iidx_watchdog_start(uint8_t node_id)
|
||||
msg.cmd.raw[1] = 112;
|
||||
|
||||
if (!aciodrv_send_and_recv(
|
||||
&msg, offsetof(struct ac_io_message, cmd.raw) + 2
|
||||
device, &msg, offsetof(struct ac_io_message, cmd.raw) + 2
|
||||
)) {
|
||||
log_warning("Starting watchdog failed"); return false;
|
||||
}
|
||||
@@ -66,13 +72,13 @@ static bool bio2drv_bi2a_iidx_watchdog_start(uint8_t node_id)
|
||||
*/
|
||||
}
|
||||
|
||||
bool bio2drv_bi2a_iidx_init(uint8_t node_id)
|
||||
bool bio2drv_bi2a_iidx_init(struct aciodrv_device_ctx *device, uint8_t node_id)
|
||||
{
|
||||
if (!bio2drv_bi2a_iidx_init_io(node_id)) {
|
||||
if (!bio2drv_bi2a_iidx_init_io(device, node_id)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!bio2drv_bi2a_iidx_watchdog_start(node_id)) {
|
||||
if (!bio2drv_bi2a_iidx_watchdog_start(device, node_id)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -80,6 +86,7 @@ bool bio2drv_bi2a_iidx_init(uint8_t node_id)
|
||||
}
|
||||
|
||||
bool bio2drv_bi2a_iidx_poll(
|
||||
struct aciodrv_device_ctx *device,
|
||||
uint8_t node_id,
|
||||
const struct bi2a_iidx_state_out *pout,
|
||||
struct bi2a_iidx_state_in *pin)
|
||||
@@ -93,7 +100,9 @@ bool bio2drv_bi2a_iidx_poll(
|
||||
*(struct bi2a_iidx_state_out *) msg.cmd.raw = *pout;
|
||||
|
||||
if (!aciodrv_send_and_recv(
|
||||
&msg, offsetof(struct ac_io_message, cmd.raw) + sizeof(*pin))) {
|
||||
device,
|
||||
&msg,
|
||||
offsetof(struct ac_io_message, cmd.raw) + sizeof(*pin))) {
|
||||
log_warning("Polling of node %d failed", node_id + 1);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1,22 +1,28 @@
|
||||
#ifndef BIO2DRV_BI2A_IIDX_H
|
||||
#define BIO2DRV_BI2A_IIDX_H
|
||||
|
||||
#include "aciodrv/device.h"
|
||||
|
||||
#include "bio2/bi2a-iidx.h"
|
||||
|
||||
/**
|
||||
* Initialize a BI2A node.
|
||||
*
|
||||
* @param device Context of opened device
|
||||
* @param node_id Id of the node to initialize (0 based).
|
||||
* @return True if successful, false on error.
|
||||
* @note This module is supposed to be used in combination with the common
|
||||
* device driver foundation.
|
||||
* @see driver.h
|
||||
*/
|
||||
bool bio2drv_bi2a_iidx_init(uint8_t node_id);
|
||||
bool bio2drv_bi2a_iidx_init(
|
||||
struct aciodrv_device_ctx *device,
|
||||
uint8_t node_id);
|
||||
|
||||
/**
|
||||
* Poll the BI2A board
|
||||
*
|
||||
* @param device Context of opened device
|
||||
* @param node_id Id of the node to query (0 based).
|
||||
* @param state Pointer to a state struct to return the current state to
|
||||
* (optional, NULL for none).
|
||||
@@ -26,6 +32,7 @@ bool bio2drv_bi2a_iidx_init(uint8_t node_id);
|
||||
* @see driver.h
|
||||
*/
|
||||
bool bio2drv_bi2a_iidx_poll(
|
||||
struct aciodrv_device_ctx *device,
|
||||
uint8_t node_id,
|
||||
const struct bi2a_iidx_state_out *pout,
|
||||
struct bi2a_iidx_state_in *pin);
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
static const uint8_t _BIO2DR_BI2A_SDVX_INIT_DATA = 0x3B;
|
||||
|
||||
// this is probably InitIO
|
||||
static bool bio2drv_bi2a_sdvx_init_io(uint8_t node_id)
|
||||
static bool bio2drv_bi2a_sdvx_init_io(struct aciodrv_device_ctx *device, uint8_t node_id)
|
||||
{
|
||||
struct ac_io_message msg;
|
||||
|
||||
@@ -22,7 +22,9 @@ static bool bio2drv_bi2a_sdvx_init_io(uint8_t node_id)
|
||||
msg.cmd.param = _BIO2DR_BI2A_SDVX_INIT_DATA;
|
||||
|
||||
if (!aciodrv_send_and_recv(
|
||||
&msg, offsetof(struct ac_io_message, cmd.raw) + 1)) {
|
||||
device,
|
||||
&msg,
|
||||
offsetof(struct ac_io_message, cmd.raw) + 1)) {
|
||||
log_warning("Init node failed");
|
||||
return 0;
|
||||
}
|
||||
@@ -32,7 +34,7 @@ static bool bio2drv_bi2a_sdvx_init_io(uint8_t node_id)
|
||||
return 1;
|
||||
}
|
||||
|
||||
static bool bio2drv_bi2a_sdvx_watchdog_start(uint8_t node_id)
|
||||
static bool bio2drv_bi2a_sdvx_watchdog_start(struct aciodrv_device_ctx *device, uint8_t node_id)
|
||||
{
|
||||
// exit early and don't actually call watchdog
|
||||
// the watchdog call actually returns different sized packets depending on
|
||||
@@ -65,6 +67,7 @@ static bool bio2drv_bi2a_sdvx_watchdog_start(uint8_t node_id)
|
||||
}
|
||||
|
||||
bool bio2drv_bi2a_sdvx_amp(
|
||||
struct aciodrv_device_ctx *device,
|
||||
uint8_t node_id,
|
||||
uint8_t unused_1,
|
||||
uint8_t unused_2,
|
||||
@@ -86,7 +89,9 @@ bool bio2drv_bi2a_sdvx_amp(
|
||||
msg.cmd.raw[3] = right;
|
||||
|
||||
if (!aciodrv_send_and_recv(
|
||||
&msg, offsetof(struct ac_io_message, cmd.raw) + 1)) {
|
||||
device,
|
||||
&msg,
|
||||
offsetof(struct ac_io_message, cmd.raw) + 1)) {
|
||||
log_warning("Setting AMP failed");
|
||||
return false;
|
||||
}
|
||||
@@ -96,17 +101,17 @@ bool bio2drv_bi2a_sdvx_amp(
|
||||
return true;
|
||||
}
|
||||
|
||||
bool bio2drv_bi2a_sdvx_init(uint8_t node_id)
|
||||
bool bio2drv_bi2a_sdvx_init(struct aciodrv_device_ctx *device, uint8_t node_id)
|
||||
{
|
||||
if (!bio2drv_bi2a_sdvx_init_io(node_id)) {
|
||||
if (!bio2drv_bi2a_sdvx_init_io(device, node_id)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!bio2drv_bi2a_sdvx_watchdog_start(node_id)) {
|
||||
if (!bio2drv_bi2a_sdvx_watchdog_start(device, node_id)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!bio2drv_bi2a_sdvx_amp(node_id, 0, 0, 0, 0)) {
|
||||
if (!bio2drv_bi2a_sdvx_amp(device, node_id, 0, 0, 0, 0)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -114,6 +119,7 @@ bool bio2drv_bi2a_sdvx_init(uint8_t node_id)
|
||||
}
|
||||
|
||||
bool bio2drv_bi2a_sdvx_poll(
|
||||
struct aciodrv_device_ctx *device,
|
||||
uint8_t node_id,
|
||||
const struct bi2a_sdvx_state_out *pout,
|
||||
struct bi2a_sdvx_state_in *pin)
|
||||
@@ -127,7 +133,9 @@ bool bio2drv_bi2a_sdvx_poll(
|
||||
*(struct bi2a_sdvx_state_out *) msg.cmd.raw = *pout;
|
||||
|
||||
if (!aciodrv_send_and_recv(
|
||||
&msg, offsetof(struct ac_io_message, cmd.raw) + sizeof(*pin))) {
|
||||
device,
|
||||
&msg,
|
||||
offsetof(struct ac_io_message, cmd.raw) + sizeof(*pin))) {
|
||||
log_warning("Polling of node %d failed", node_id + 1);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1,22 +1,28 @@
|
||||
#ifndef BIO2DRV_BI2A_H
|
||||
#define BIO2DRV_BI2A_H
|
||||
#ifndef BIO2DRV_BI2A_SDVX_H
|
||||
#define BIO2DRV_BI2A_SDVX_H
|
||||
|
||||
#include "aciodrv/device.h"
|
||||
|
||||
#include "bio2/bi2a-sdvx.h"
|
||||
|
||||
/**
|
||||
* Initialize a BI2A node.
|
||||
*
|
||||
* @param device Context of opened device
|
||||
* @param node_id Id of the node to initialize (0 based).
|
||||
* @return True if successful, false on error.
|
||||
* @note This module is supposed to be used in combination with the common
|
||||
* device driver foundation.
|
||||
* @see driver.h
|
||||
*/
|
||||
bool bio2drv_bi2a_sdvx_init(uint8_t node_id);
|
||||
bool bio2drv_bi2a_sdvx_init(
|
||||
struct aciodrv_device_ctx *device,
|
||||
uint8_t node_id);
|
||||
|
||||
/**
|
||||
* Poll the board
|
||||
*
|
||||
* @param device Context of opened device
|
||||
* @param node_id Id of the node to query (0 based).
|
||||
* @param state Pointer to a state struct to return the current state to
|
||||
* (optional, NULL for none).
|
||||
@@ -26,6 +32,7 @@ bool bio2drv_bi2a_sdvx_init(uint8_t node_id);
|
||||
* @see driver.h
|
||||
*/
|
||||
bool bio2drv_bi2a_sdvx_poll(
|
||||
struct aciodrv_device_ctx *device,
|
||||
uint8_t node_id,
|
||||
const struct bi2a_sdvx_state_out *pout,
|
||||
struct bi2a_sdvx_state_in *pin);
|
||||
@@ -33,6 +40,7 @@ bool bio2drv_bi2a_sdvx_poll(
|
||||
/**
|
||||
* Set the BIO2 BI2A SDVX digital amp level
|
||||
*
|
||||
* @param device Context of opened device
|
||||
* @param node_id Id of the node to query (0 based).
|
||||
* @param primary primary volume (96-0)
|
||||
* @param headphone headphone volume (96-0)
|
||||
@@ -42,6 +50,7 @@ bool bio2drv_bi2a_sdvx_poll(
|
||||
* @note Note 96 is lowest volume level, 0 is highest
|
||||
*/
|
||||
bool bio2drv_bi2a_sdvx_amp(
|
||||
struct aciodrv_device_ctx *device,
|
||||
uint8_t node_id,
|
||||
uint8_t unused_1,
|
||||
uint8_t unused_2,
|
||||
|
||||
Reference in New Issue
Block a user