fix formatting, fix bitfield offsets

This commit is contained in:
hanatonikkou 2026-04-28 20:01:34 +02:00
parent 4bb8b55777
commit d69a03393b
6 changed files with 238 additions and 220 deletions

View file

@ -377,9 +377,13 @@ impl ClockManagerImpl {
// check the clock muxes to select the right source for clktop
let mux0 = sysctrl.r(utra::sysctrl::SFR_CGUSEL0) & 0x1;
let mux1 = sysctrl.r(utra::sysctrl::SFR_CGUSEL1) & 0x1;
let clktop = if mux0 == 1 { pll0_freq }
else if mux1 == 1 { XTAL0 }
else { OSC };
let clktop = if mux0 == 1 {
pll0_freq
} else if mux1 == 1 {
XTAL0
} else {
OSC
};
let fclk_fd = sysctrl.r(utra::sysctrl::SFR_CGUFD_CFGFDCR_0_4_0) & 0xFF;
let aclk_fd = sysctrl.r(utra::sysctrl::SFR_CGUFD_CFGFDCR_0_4_1) & 0xFF;
let hclk_fd = sysctrl.r(utra::sysctrl::SFR_CGUFD_CFGFDCR_0_4_2) & 0xFF;
@ -455,9 +459,13 @@ impl ClockManagerImpl {
// check the clock muxes to select the right source for clktop
let mux0 = self.sysctrl.r(utra::sysctrl::SFR_CGUSEL0) & 0x1;
let mux1 = self.sysctrl.r(utra::sysctrl::SFR_CGUSEL1) & 0x1;
let clktop = if mux0 == 1 { pll0_freq }
else if mux1 == 1 { XTAL0 }
else { OSC };
let clktop = if mux0 == 1 {
pll0_freq
} else if mux1 == 1 {
XTAL0
} else {
OSC
};
let fclk_fd = self.sysctrl.r(utra::sysctrl::SFR_CGUFD_CFGFDCR_0_4_0) & 0xFF;
let aclk_fd = self.sysctrl.r(utra::sysctrl::SFR_CGUFD_CFGFDCR_0_4_1) & 0xFF;
let hclk_fd = self.sysctrl.r(utra::sysctrl::SFR_CGUFD_CFGFDCR_0_4_2) & 0xFF;

View file

@ -1,25 +1,20 @@
#[allow(unused)] // time::Duration is needed in send_read but the compiler doesn't realize it
use std::time::{Duration, Instant};
use arbitrary_int::{Number, u5};
use bao1x_api::bio::*;
use bao1x_api::bio_code;
use bao1x_api::bio_resources::*;
use bao1x_hal::bio::{Bio, CoreCsr};
use bao1x_hal::clocks::ClockOp;
use num_traits::cast::{ToPrimitive};
#[allow(unused)] // time::Duration is needed in send_read but the compiler doesn't realize it
use std::time::{Duration, Instant};
use num_traits::cast::ToPrimitive;
use utralib::generated::utra::bio_bdma;
use xous_api_susres::api::Opcode as SusresOp;
mod protocol;
use protocol::*;
pub use protocol::{
Address,
Brightness,
Command,
Part207LedDriver,
SpecialCommand101,
SpecialCommand110,
SpecCmdData,
Address, Brightness, Command, Part207LedDriver, SpecCmdData, SpecialCommand101, SpecialCommand110,
bitflags,
};
@ -29,7 +24,7 @@ pub use protocol::{
* Dali stands for Digitally Addressable Lighting Interface and is a standard for controlling building
* lighting. The naming convention is a bit confusing:
*
* Application controller A bus master, used to control lighting: that's what this library is form
* Application controller A bus master, used to control lighting: that's what this library is for
* Control gear A device directly controlling lights, e.g. an LED driver
* Control device An input device, e.g. a light sensor or a dimmer
*
@ -53,8 +48,8 @@ pub use protocol::{
*
* Limitations of this library:
* 1) It's not been tested with actual devices.
* 2) Not all device types are implemented. To add a new device type, implement an enum with trait DataByte,
* equivalent to Extension207LedDriver.
* 2) Not all device types are implemented. To add a new device type, implement an enum with trait
* DataByte, equivalent to Extension207LedDriver.
* 3) DALI-2 adds support for control devices such as sensors and dimmers, which are not supported.
* 4) Only synchronous functions at this point.
*
@ -110,8 +105,8 @@ impl From<ResourceError> for DaliSetupError {
#[derive(PartialEq)]
pub enum InvertTx {
// A level shifter for interfacing with the bus may invert the signal (e.g. a transistor pulling the line
// low on a high pin ) or not (e.g. an opto-isolator).
// A level shifter for interfacing with the bus may invert the signal (e.g. a transistor pulling the
// line low on a high pin ) or not (e.g. an opto-isolator).
True,
False,
}
@ -126,13 +121,10 @@ pub struct DaliConfig {
#[allow(unused)] // never used, says the compiler
impl DaliConfig {
pub fn new(rx_pin: u5, tx_pin: u5) -> Result<Self, DaliSetupError> {
if rx_pin == tx_pin { return Err(DaliSetupError::TxRxPinsIdentical); }
Ok(Self {
rx_pin,
tx_pin,
io_mode: IoConfigMode::Overwrite,
inverts: InvertTx::False,
})
if rx_pin == tx_pin {
return Err(DaliSetupError::TxRxPinsIdentical);
}
Ok(Self { rx_pin, tx_pin, io_mode: IoConfigMode::Overwrite, inverts: InvertTx::False })
}
}
@ -176,15 +168,14 @@ impl Drop for Dali {
}
impl Dali {
pub fn new(config: DaliConfig) -> Result<Dali, DaliSetupError>
{
pub fn new(config: DaliConfig) -> Result<Dali, DaliSetupError> {
let rx_pin = config.rx_pin;
let tx_pin = config.tx_pin;
// Lower fclk speed to allow longer quantum intervals, any freqency below 157MHz works
let requested_frequency = 140_000_000;
let xns = xous_names::XousNames::new().unwrap();
let conn = xns.request_connection_blocking(xous_api_susres::api::SERVER_NAME_SUSRES)
let conn = xns
.request_connection_blocking(xous_api_susres::api::SERVER_NAME_SUSRES)
.expect("Can't connect to Susres server");
let result = xous::send_message(
conn,
@ -194,11 +185,14 @@ impl Dali {
requested_frequency as usize,
0,
0,
));
),
);
match result {
Ok(xous::Result::Scalar2(ok, _freq)) => {
if ok == 0 { return Err(DaliSetupError::CantChangeFclk); }
},
if ok == 0 {
return Err(DaliSetupError::CantChangeFclk);
}
}
_ => return Err(DaliSetupError::CantChangeFclk),
};
@ -207,9 +201,8 @@ impl Dali {
let resource_grant = bio_ss.claim_resources(&Dali::resource_spec())?;
log::debug!("granted to Dali: {:?}", resource_grant);
// configure cores
let config_rx = CoreConfig {
clock_mode: bao1x_api::bio::ClockMode::ExternalPin(BioPin::new(rx_pin.as_u8()))
};
let config_rx =
CoreConfig { clock_mode: bao1x_api::bio::ClockMode::ExternalPin(BioPin::new(rx_pin.as_u8())) };
let config_tx = CoreConfig { clock_mode: bao1x_api::bio::ClockMode::TargetFreqFrac(2400) };
let rx_kernel = dali_rx_kernel();
let tx_kernel = dali_tx_kernel();
@ -219,7 +212,9 @@ impl Dali {
bio_ss.claim_dynamic_pin(rx_pin.as_u8(), &Dali::resource_spec().claimer)?;
bio_ss.claim_dynamic_pin(tx_pin.as_u8(), &Dali::resource_spec().claimer)?;
let mut io_config = IoConfig::default();
if config.inverts == InvertTx::True { io_config.o_inv = 1 << tx_pin.as_u32(); }
if config.inverts == InvertTx::True {
io_config.o_inv = 1 << tx_pin.as_u32();
}
io_config.mapped = (1 << rx_pin.as_u32()) | (1 << tx_pin.as_u32());
io_config.mode = config.io_mode;
bio_ss.setup_io_config(io_config).unwrap();
@ -263,8 +258,11 @@ impl Dali {
}
}
fn send_sync(&mut self, address_byte: impl AddrByte, data_byte: impl DataByte) ->
Result<(), DaliOpError> {
fn send_sync(
&mut self,
address_byte: impl AddrByte,
data_byte: impl DataByte,
) -> Result<(), DaliOpError> {
self.empty_read_queue();
let cmd = ForwardFrame::new(address_byte, data_byte).to_bits();
log::debug!("sending: {:08b}_{:08b}", cmd >> 8, cmd & 0xff);
@ -278,95 +276,111 @@ impl Dali {
}
}
fn send_read(&mut self, address_byte: impl AddrByte, data_byte: impl DataByte) ->
Result<BackwardFrame, DaliOpError> {
let _ = self.send_sync(address_byte, data_byte)?;
let now = Instant::now();
// wait time
// (last bit transition -> value pushed onto FIFO) --
// value pushed onto FIFO -> end of stop bits 1250us
// end of stop bits -> max. var. delay for backward frames 9166us
while self.rx.csr.rf(bio_bdma::SFR_FLEVEL_PCLK_REGFIFO_LEVEL1) == 0 &&
now.elapsed().as_micros() < 10416 {}
// due to min. delay for backward frames and their length, it's unlikely a transmission finishes
// before the end of this timeout
let read = if self.rx.csr.rf(bio_bdma::SFR_FLEVEL_PCLK_REGFIFO_LEVEL1) != 0 {
// message received -> read
self.rx.csr.r(bio_bdma::SFR_RXF1) & 0x0000_00ff
} else if self.rx.csr.rf(bio_bdma::SFR_EVENT_STATUS_SFR_EVENT_STATUS) & 0b11 == 0 {
// line busy, external source -> wait for message
while self.rx.csr.rf(bio_bdma::SFR_FLEVEL_PCLK_REGFIFO_LEVEL1) == 0 {};
self.rx.csr.r(bio_bdma::SFR_RXF1) & 0x0000_00ff
} else {
// line idle -> timeout
// line busy, tx core is sending -> timeout
0
};
if read == 0 {
log::debug!("received: --timeout--");
} else {
log::debug!("received: {:08b}_{:08b}_{:08b}_{:08b}",
(read >> 24), (read >> 16) & 0xff, (read >> 8) & 0xff, read & 0xff
);
}
return Ok(BackwardFrame(read as u8))
fn send_read(
&mut self,
address_byte: impl AddrByte,
data_byte: impl DataByte,
) -> Result<BackwardFrame, DaliOpError> {
let _ = self.send_sync(address_byte, data_byte)?;
let now = Instant::now();
// wait time
// (last bit transition -> value pushed onto FIFO) --
// value pushed onto FIFO -> end of stop bits 1250us
// end of stop bits -> max. var. delay for backward frames 9166us
while self.rx.csr.rf(bio_bdma::SFR_FLEVEL_PCLK_REGFIFO_LEVEL1) == 0
&& now.elapsed().as_micros() < 10416
{}
// due to min. delay for backward frames and their length, it's unlikely a transmission finishes
// before the end of this timeout
let read = if self.rx.csr.rf(bio_bdma::SFR_FLEVEL_PCLK_REGFIFO_LEVEL1) != 0 {
// message received -> read
self.rx.csr.r(bio_bdma::SFR_RXF1) & 0x0000_00ff
} else if self.rx.csr.rf(bio_bdma::SFR_EVENT_STATUS_SFR_EVENT_STATUS) & 0b11 == 0 {
// line busy, external source -> wait for message
while self.rx.csr.rf(bio_bdma::SFR_FLEVEL_PCLK_REGFIFO_LEVEL1) == 0 {}
self.rx.csr.r(bio_bdma::SFR_RXF1) & 0x0000_00ff
} else {
// line idle -> timeout
// line busy, tx core is sending -> timeout
0
};
if read == 0 {
log::debug!("received: --timeout--");
} else {
log::debug!(
"received: {:08b}_{:08b}_{:08b}_{:08b}",
(read >> 24),
(read >> 16) & 0xff,
(read >> 8) & 0xff,
read & 0xff
);
}
return Ok(BackwardFrame(read as u8));
}
pub fn set_brightness(&mut self, address: Address, brightness: Brightness) ->
Result<(), DaliOpError> {
_ = self.send_sync(address, brightness)?;
Ok(())
pub fn set_brightness(&mut self, address: Address, brightness: Brightness) -> Result<(), DaliOpError> {
_ = self.send_sync(address, brightness)?;
Ok(())
}
pub fn send_command(&mut self, address: Address, command: impl StdCommand + DataByte) ->
Result<(), DaliOpError> {
_ = self.send_sync(address, command)?;
Ok(())
pub fn send_command(
&mut self,
address: Address,
command: impl StdCommand + DataByte,
) -> Result<(), DaliOpError> {
_ = self.send_sync(address, command)?;
Ok(())
}
pub fn query_command_value(&mut self, address: Address, command: impl StdCommand + DataByte) ->
Result<u8, DaliOpError> {
let response = self.send_read(address, command)?;
Ok(response.0)
pub fn query_command_value(
&mut self,
address: Address,
command: impl StdCommand + DataByte,
) -> Result<u8, DaliOpError> {
let response = self.send_read(address, command)?;
Ok(response.0)
}
pub fn query_command_bool(&mut self, address: Address, command: impl StdCommand + DataByte) ->
Result<bool, DaliOpError> {
let response = self.send_read(address, command)?;
if response.0 != 0 {
Ok(true)
} else {
Ok(false)
}
pub fn query_command_bool(
&mut self,
address: Address,
command: impl StdCommand + DataByte,
) -> Result<bool, DaliOpError> {
let response = self.send_read(address, command)?;
if response.0 != 0 { Ok(true) } else { Ok(false) }
}
pub fn send_special_command<Trait: SpecialCommand + AddrByte>
(&mut self, command: Trait, data: SpecCmdData) -> Result<(), DaliOpError> {
let data_byte = command.match_data_byte(data)?;
_ = self.send_sync(command, data_byte)?;
Ok(())
pub fn send_special_command<Trait: SpecialCommand + AddrByte>(
&mut self,
command: Trait,
data: SpecCmdData,
) -> Result<(), DaliOpError> {
let data_byte = command.match_data_byte(data)?;
_ = self.send_sync(command, data_byte)?;
Ok(())
}
pub fn query_special_command_value<Trait: SpecialCommand + AddrByte>
(&mut self, command: Trait, data: SpecCmdData) -> Result<u8, DaliOpError> {
let data_byte = command.match_data_byte(data)?;
let response = self.send_read(command, data_byte)?;
Ok(response.0)
pub fn query_special_command_value<Trait: SpecialCommand + AddrByte>(
&mut self,
command: Trait,
data: SpecCmdData,
) -> Result<u8, DaliOpError> {
let data_byte = command.match_data_byte(data)?;
let response = self.send_read(command, data_byte)?;
Ok(response.0)
}
pub fn query_special_command_bool<Trait: SpecialCommand + AddrByte>
(&mut self, command: Trait, data: SpecCmdData) -> Result<bool, DaliOpError> {
let data_byte = command.match_data_byte(data)?;
let response = self.send_read(command, data_byte)?;
if response.0 != 0 {
Ok(true)
} else {
Ok(false)
}
pub fn query_special_command_bool<Trait: SpecialCommand + AddrByte>(
&mut self,
command: Trait,
data: SpecCmdData,
) -> Result<bool, DaliOpError> {
let data_byte = command.match_data_byte(data)?;
let response = self.send_read(command, data_byte)?;
if response.0 != 0 { Ok(true) } else { Ok(false) }
}
}
#[rustfmt::skip]
bio_code!(dali_rx_kernel, DALI_RX_START, DALI_RX_END,
/* DALI receiver

View file

@ -1,10 +1,12 @@
use arbitrary_int::{Number, u4, u6};
use super::DaliOpError;
/* Overview:
*
* Two-layer structure allows user-facing functions of form (address, command) or (command, data) that work
* with all possible input combinations while preventing misformed frames. Alternative would be nested enums.
* with all possible input combinations while preventing misformed frames. Alternative would be nested
* enums.
*
* User-facing structures:
* Address byte:
@ -41,6 +43,7 @@ pub enum Address {
GroupAddress(u4),
}
#[rustfmt::skip]
#[derive(Clone, Copy, Debug)]
pub enum Command {
// Arc power control commands
@ -182,7 +185,7 @@ pub enum Command {
QueryManufacturerSpecificMode = 166, // * (part of Dali-2)
QueryNextDeviceType = 167, // *
QueryExtendedFadeTime = 168, // *
QueryControlGearFailure = 169, // *
QueryControlGearFailure = 169, // *
// Reserved 170-175
QueryLevelScene0 = 176, // 0xb0
QueryLevelScene1 = 177,
@ -210,6 +213,7 @@ pub enum Command {
// Extended Commands 224-255
}
#[rustfmt::skip]
#[derive(Clone, Copy, Debug)]
pub enum Part207LedDriver {
ReferenceSystemPower = 224,
@ -239,6 +243,7 @@ pub enum Part207LedDriver {
QueryExtendedVersionNumber = 255,
}
#[rustfmt::skip]
#[derive(Clone, Copy, Debug)]
pub enum SpecialCommand101 {
// Recommended to send Initialize and Randomize twice.
@ -264,6 +269,7 @@ pub enum SpecialCommand101 {
// Reserved 15
}
#[rustfmt::skip]
#[derive(Clone, Copy, Debug)]
pub enum SpecialCommand110 {
EnableDeviceType = 0, // #272 - maybe selects function of Extended***Set-commands?
@ -297,7 +303,7 @@ pub enum GroupBit {
#[derive(Clone, Copy, Debug)]
pub enum CommandBit {
DirectArcPowerCommand = 0,
OtherCommand= 1,
OtherCommand = 1,
}
#[derive(Clone, Copy, Debug)]
@ -312,9 +318,7 @@ pub struct BackwardFrame(pub u8);
// Trait for ForwardFrame constructor
pub trait AddrByte {
fn to_bits(&self) -> u8;
fn set_group_bit(&self) -> GroupBit {
GroupBit::GroupAddress
}
fn set_group_bit(&self) -> GroupBit { GroupBit::GroupAddress }
}
impl AddrByte for Address {
@ -325,6 +329,7 @@ impl AddrByte for Address {
Address::GroupAddress(grp) => grp.as_u8() << 1,
}
}
fn set_group_bit(&self) -> GroupBit {
match self {
Address::ShortAddress(_) => GroupBit::ShortAddress,
@ -350,36 +355,34 @@ impl AddrByte for SpecialCommand110 {
// Trait for ForwardFrame constructor
pub trait DataByte {
fn to_bits(&self) -> u8;
fn set_command_bit(&self) -> CommandBit {
CommandBit::OtherCommand
}
fn set_command_bit(&self) -> CommandBit { CommandBit::OtherCommand }
}
impl DataByte for Brightness {
fn to_bits(&self) -> u8 { self.0 }
fn set_command_bit(&self) -> CommandBit {
CommandBit::DirectArcPowerCommand
}
fn set_command_bit(&self) -> CommandBit { CommandBit::DirectArcPowerCommand }
}
impl DataByte for SpCmdData {
fn to_bits(&self) -> u8 { self.0 }
}
impl DataByte for Command {
fn to_bits(&self) -> u8 { *self as u8 }
}
impl DataByte for Part207LedDriver {
fn to_bits(&self) -> u8 { *self as u8 }
}
impl DataByte for SpCmdData { fn to_bits(&self) -> u8 { self.0 } }
impl DataByte for Command { fn to_bits(&self) -> u8 { *self as u8 } }
impl DataByte for Part207LedDriver { fn to_bits(&self) -> u8 { *self as u8 } }
impl ForwardFrame {
pub fn new (address: impl AddrByte, data: impl DataByte) -> Self {
pub fn new(address: impl AddrByte, data: impl DataByte) -> Self {
let group_bit = address.set_group_bit();
let address_bits = address.to_bits();
let command_bit = data.set_command_bit();
let address_byte = (group_bit as u8) << 7 | address_bits | command_bit as u8;
Self {
address_byte,
data_byte: data.to_bits(),
}
Self { address_byte, data_byte: data.to_bits() }
}
pub fn to_bits (&self) -> u16 {
(self.address_byte as u16) << 8 | self.data_byte as u16
}
pub fn to_bits(&self) -> u16 { (self.address_byte as u16) << 8 | self.data_byte as u16 }
}
// User-facing trait to send special commands
@ -390,47 +393,38 @@ pub trait SpecialCommand {
impl SpecialCommand for SpecialCommand101 {
fn match_data_byte(&self, data: SpecCmdData) -> Result<SpCmdData, DaliOpError> {
match self {
SpecialCommand101::Terminate |
SpecialCommand101::Randomize |
SpecialCommand101::Compare |
SpecialCommand101::Withdraw |
SpecialCommand101::QueryShortAddress |
SpecialCommand101::PhysicalSelection |
SpecialCommand101::Ping => {
match data {
SpecCmdData::None => Ok(SpCmdData(0)),
_ => Err(DaliOpError::WrongDataByteForCommand),
}
SpecialCommand101::Terminate
| SpecialCommand101::Randomize
| SpecialCommand101::Compare
| SpecialCommand101::Withdraw
| SpecialCommand101::QueryShortAddress
| SpecialCommand101::PhysicalSelection
| SpecialCommand101::Ping => match data {
SpecCmdData::None => Ok(SpCmdData(0)),
_ => Err(DaliOpError::WrongDataByteForCommand),
},
SpecialCommand101::ProgramShortAddress |
SpecialCommand101::VerifyShortAddress => {
match data {
SpecCmdData::Address(addr) => {
let byte = addr.as_u8() << 1 | 0b0000_0001;
Ok(SpCmdData(byte))
}
_ => Err(DaliOpError::WrongDataByteForCommand),
SpecialCommand101::ProgramShortAddress | SpecialCommand101::VerifyShortAddress => match data {
SpecCmdData::Address(addr) => {
let byte = addr.as_u8() << 1 | 0b0000_0001;
Ok(SpCmdData(byte))
}
_ => Err(DaliOpError::WrongDataByteForCommand),
},
SpecialCommand101::Initialize => {
match data {
SpecCmdData::InitializeBroadcast => Ok(SpCmdData(0b0000_0000)),
SpecCmdData::InitializeShortAddress(addr) => {
let byte = addr.as_u8() << 1 | 0b0000_0001;
Ok(SpCmdData(byte))
},
SpecCmdData::InitializeDeviceWithoutShortAddress => Ok(SpCmdData(0b1111_1111)),
_ => Err(DaliOpError::WrongDataByteForCommand),
SpecialCommand101::Initialize => match data {
SpecCmdData::InitializeBroadcast => Ok(SpCmdData(0b0000_0000)),
SpecCmdData::InitializeShortAddress(addr) => {
let byte = addr.as_u8() << 1 | 0b0000_0001;
Ok(SpCmdData(byte))
}
SpecCmdData::InitializeDeviceWithoutShortAddress => Ok(SpCmdData(0b1111_1111)),
_ => Err(DaliOpError::WrongDataByteForCommand),
},
SpecialCommand101::DataTransferRegister0 |
SpecialCommand101::SearchAddressH |
SpecialCommand101::SearchAddressM |
SpecialCommand101::SearchAddressL => {
match data {
SpecCmdData::Data(data) => Ok(SpCmdData(data)),
_ => Err(DaliOpError::WrongDataByteForCommand),
}
SpecialCommand101::DataTransferRegister0
| SpecialCommand101::SearchAddressH
| SpecialCommand101::SearchAddressM
| SpecialCommand101::SearchAddressL => match data {
SpecCmdData::Data(data) => Ok(SpCmdData(data)),
_ => Err(DaliOpError::WrongDataByteForCommand),
},
}
}
@ -452,66 +446,67 @@ impl StdCommand for Command {}
impl StdCommand for Part207LedDriver {}
// Information to decode backward frames
#[rustfmt::skip]
pub mod bitflags {
pub mod std {
pub mod status_info {
pub const STATUS_OF_CONTROL_GEAR: u8 = 1;
pub const LAMP_FAILURE: u8 = 2;
pub const LAMP_ARC_POWER_ON: u8 = 3;
pub const QUERY_LIMIT_ERROR: u8 = 4;
pub const FADE_RUNNING: u8 = 5;
pub const QUERY_RESET_STATE: u8 = 6;
pub const QUERY_MISSING_SHORT_ADDRESS: u8 = 7;
pub const QUERY_POWER_FAILURE: u8 = 8;
pub const STATUS_OF_CONTROL_GEAR: u8 = 0x01;
pub const LAMP_FAILURE: u8 = 0x02;
pub const LAMP_ARC_POWER_ON: u8 = 0x04;
pub const QUERY_LIMIT_ERROR: u8 = 0x08;
pub const FADE_RUNNING: u8 = 0x10;
pub const QUERY_RESET_STATE: u8 = 0x20;
pub const QUERY_MISSING_SHORT_ADDRESS: u8 = 0x40;
pub const QUERY_POWER_FAILURE: u8 = 0x80;
}
pub mod lamp_failure {
pub const SHORT_CIRCUIT: u8 = 1;
pub const OPEN_CIRCUIT: u8 = 2;
pub const LOAD_DECREASE: u8 = 3;
pub const LOAD_INCREASE: u8 = 4;
pub const CURRENT_PROTECTOR_ACTIVE: u8 = 5;
pub const SHORT_CIRCUIT: u8 = 0x01;
pub const OPEN_CIRCUIT: u8 = 0x02;
pub const LOAD_DECREASE: u8 = 0x04;
pub const LOAD_INCREASE: u8 = 0x08;
pub const CURRENT_PROTECTOR_ACTIVE: u8 = 0x10;
}
}
pub mod part_207_led_driver {
pub mod gear_type {
pub const LED_POWER_SUPPLY_INTEGRATED: u8 = 1;
pub const LED_MODULE_INTEGRATED: u8 = 2;
pub const AC_SUPPLY_POSSIBLE: u8 = 3;
pub const DC_SUPPLY_POSSIBLE: u8 = 4;
pub const LED_POWER_SUPPLY_INTEGRATED: u8 = 0x01;
pub const LED_MODULE_INTEGRATED: u8 = 0x02;
pub const AC_SUPPLY_POSSIBLE: u8 = 0x04;
pub const DC_SUPPLY_POSSIBLE: u8 = 0x08;
// Bits 4-7 unused
}
pub mod possible_operating_mode {
pub const PWM_MODE_IS_POSSIBLE: u8 = 1;
pub const AM_MODE_IS_POSSIBLE: u8 = 2;
pub const OUTPUT_IS_CURRENT_CONTROLLED: u8 = 3;
pub const HIGH_CURRENT_PULSE_MODE: u8 = 4;
pub const PWM_MODE_IS_POSSIBLE: u8 = 0x01;
pub const AM_MODE_IS_POSSIBLE: u8 = 0x02;
pub const OUTPUT_IS_CURRENT_CONTROLLED: u8 = 0x04;
pub const HIGH_CURRENT_PULSE_MODE: u8 = 0x08;
// Bits 4-7 unused
}
pub mod features {
pub const SHORT_CIRCUIT_DETECTION_CAN_BE_QUERIED: u8 = 1;
pub const OPEN_CIRCUIT_DETECTION_CAN_BE_QUERIED: u8 = 2;
pub const DETECTION_OF_LOAD_DECREASE_CAN_BE_QUERIED: u8 = 3;
pub const DETECTION_OF_LOAD_INCREASE_CAN_BE_QUERIED: u8 = 4;
pub const CURRENT_PROTECTOR_IS_IMPLEMENTED_AND_CAN_BE_QUERIED: u8 = 5;
pub const THERMAL_SHUTDOWN: u8 = 6;
pub const LIGHT_LEVEL_REDUCTION_DUE_TO_OVERTEMPERATURE: u8 = 7;
pub const PHYSICAL_SELECTION_IS_SUPPORTED: u8 = 8;
pub const SHORT_CIRCUIT_DETECTION_CAN_BE_QUERIED: u8 = 0x01;
pub const OPEN_CIRCUIT_DETECTION_CAN_BE_QUERIED: u8 = 0x02;
pub const DETECTION_OF_LOAD_DECREASE_CAN_BE_QUERIED: u8 = 0x04;
pub const DETECTION_OF_LOAD_INCREASE_CAN_BE_QUERIED: u8 = 0x08;
pub const CURRENT_PROTECTOR_IS_IMPLEMENTED_AND_CAN_BE_QUERIED: u8 = 0x10;
pub const THERMAL_SHUTDOWN: u8 = 0x20;
pub const LIGHT_LEVEL_REDUCTION_DUE_TO_OVERTEMPERATURE: u8 = 0x40;
pub const PHYSICAL_SELECTION_IS_SUPPORTED: u8 = 0x80;
}
pub mod failure_modes {
pub const SHORT_CIRCUIT_DETECTION_CAN_BE_QUERIED: u8 = 1;
pub const OPEN_CIRCUIT_DETECTION_CAN_BE_QUERIED: u8 = 2;
pub const DETECTION_OF_LOAD_DECREASE_CAN_BE_QUERIED: u8 = 3;
pub const DETECTION_OF_LOAD_INCREASE_CAN_BE_QUERIED: u8 = 4;
pub const CURRENT_PROTECTOR_IS_IMPLEMENTED_AND_CAN_BE_QUERIED: u8 = 5;
pub const THERMAL_SHUTDOWN: u8 = 6;
// Bit 7-8 unused
pub const SHORT_CIRCUIT_DETECTION_CAN_BE_QUERIED: u8 = 0x01;
pub const OPEN_CIRCUIT_DETECTION_CAN_BE_QUERIED: u8 = 0x02;
pub const DETECTION_OF_LOAD_DECREASE_CAN_BE_QUERIED: u8 = 0x04;
pub const DETECTION_OF_LOAD_INCREASE_CAN_BE_QUERIED: u8 = 0x08;
pub const CURRENT_PROTECTOR_IS_IMPLEMENTED_AND_CAN_BE_QUERIED: u8 = 0x10;
pub const THERMAL_SHUTDOWN: u8 = 0x20;
// Bit 6-7 unused
}
pub mod operating_mode {
pub const PWM_MODE_ACTIVE: u8 = 1;
pub const AM_MODE_ACTIVE: u8 = 2;
pub const OUTPUT_IS_CURRENT_CONTROLLED: u8 = 3;
pub const HIGH_CURRENT_PULSE_MODE_ACTIVE: u8 = 4;
pub const NON_LOGARITHMIC_DIMMING_CURVE_ACTIVE: u8 = 5;
pub const PWM_MODE_ACTIVE: u8 = 0x01;
pub const AM_MODE_ACTIVE: u8 = 0x02;
pub const OUTPUT_IS_CURRENT_CONTROLLED: u8 = 0x04;
pub const HIGH_CURRENT_PULSE_MODE_ACTIVE: u8 = 0x08;
pub const NON_LOGARITHMIC_DIMMING_CURVE_ACTIVE: u8 = 0x10;
// Bits 5-7 unused
}
}

View file

@ -38,9 +38,9 @@ pub mod av_trng;
pub mod c;
#[cfg(feature = "captouch")]
pub mod captouch;
#[cfg(feature = "dali")]
pub mod dali;
#[cfg(feature = "mac-demo")]
pub mod mac_demo;
#[cfg(feature = "ws2812")]
pub mod ws2812;
#[cfg(feature = "dali")]
pub mod dali;

View file

@ -2,8 +2,8 @@ pub mod api;
pub mod trng;
use bao1x_api::*;
use bao1x_hal::udma::{AdcExtChannel, AdcSource};
use bao1x_hal::clocks::ClockOp;
use bao1x_hal::udma::{AdcExtChannel, AdcSource};
use num_traits::*;
use xous::{Message, send_message};
use xous_api_susres::api::Opcode as SusresOp;

View file

@ -1,13 +1,12 @@
use core::sync::atomic::{AtomicU32, Ordering};
use bao1x_api::divide_by_fd;
use bao1x_hal::clocks::{ClockOp, fd_from_frequency};
use num_traits::*;
use utralib::*;
use xous::{CID, Message, msg_blocking_scalar_unpack, msg_scalar_unpack, send_message, sender::Sender};
use xous_api_susres::*;
use xous_ipc::Buffer;
use bao1x_api::divide_by_fd;
use bao1x_hal::clocks::{fd_from_frequency,ClockOp};
static TIMEOUT_TIME: AtomicU32 = AtomicU32::new(5000);
@ -406,7 +405,9 @@ fn susres_service() {
let requested_freq = arg2 as u32;
let fclk_fd = fd_from_frequency(requested_freq, clk_mgr.clktop);
let achievable_freq = divide_by_fd(fclk_fd, clk_mgr.clktop);
if (1.0 - (achievable_freq as f32 / requested_freq as f32)).abs() < MAX_DEVIATION {
if (1.0 - (achievable_freq as f32 / requested_freq as f32)).abs()
< MAX_DEVIATION
{
clk_mgr.set_fclk_fd(fclk_fd as u8);
clk_mgr.update_clocks();
log::info!("Changed fclk to {}", clk_mgr.fclk);