mirror of
https://github.com/stakwork/sphinx-key.git
synced 2026-02-20 23:25:48 +01:00
cargo clippy
This commit is contained in:
@@ -1,28 +1,28 @@
|
||||
pub(crate) struct RGB {
|
||||
pub(crate) struct Rgb {
|
||||
pub(crate) r: u8,
|
||||
pub(crate) g: u8,
|
||||
pub(crate) b: u8,
|
||||
}
|
||||
|
||||
pub(crate) const BLUE: RGB = RGB {
|
||||
pub(crate) const BLUE: Rgb = Rgb {
|
||||
r: 00,
|
||||
g: 00,
|
||||
b: 255,
|
||||
};
|
||||
|
||||
pub(crate) const GREEN: RGB = RGB {
|
||||
pub(crate) const GREEN: Rgb = Rgb {
|
||||
r: 00,
|
||||
g: 255,
|
||||
b: 00,
|
||||
};
|
||||
|
||||
pub(crate) const ORANGE: RGB = RGB {
|
||||
pub(crate) const ORANGE: Rgb = Rgb {
|
||||
r: 255,
|
||||
g: 55,
|
||||
b: 00,
|
||||
};
|
||||
|
||||
pub(crate) const WHITE: RGB = RGB {
|
||||
pub(crate) const WHITE: Rgb = Rgb {
|
||||
r: 255,
|
||||
g: 255,
|
||||
b: 255,
|
||||
|
||||
@@ -16,30 +16,30 @@ pub(crate) fn setup(peripherals: Peripherals) -> Result<TxRmtDriver<'static>, Fa
|
||||
let led = peripherals.led;
|
||||
let channel = peripherals.channel;
|
||||
let config = TransmitConfig::new().clock_divider(1);
|
||||
let tx = TxRmtDriver::new(channel, led, &config).map_err(|e| FactoryError::EspError(e))?;
|
||||
let tx = TxRmtDriver::new(channel, led, &config).map_err(FactoryError::Esp)?;
|
||||
Ok(tx)
|
||||
}
|
||||
|
||||
pub(crate) fn setup_complete(led_tx: &mut TxRmtDriver) -> Result<(), FactoryError> {
|
||||
neopixel(BLUE, led_tx).map_err(|e| FactoryError::EspError(e))?;
|
||||
neopixel(BLUE, led_tx).map_err(FactoryError::Esp)?;
|
||||
FreeRtos::delay_ms(10);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) fn update_launch(led_tx: &mut TxRmtDriver) -> Result<(), FactoryError> {
|
||||
neopixel(ORANGE, led_tx).map_err(|e| FactoryError::EspError(e))?;
|
||||
neopixel(ORANGE, led_tx).map_err(FactoryError::Esp)?;
|
||||
FreeRtos::delay_ms(10);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) fn update_complete(led_tx: &mut TxRmtDriver) -> Result<(), FactoryError> {
|
||||
neopixel(GREEN, led_tx).map_err(|e| FactoryError::EspError(e))?;
|
||||
neopixel(GREEN, led_tx).map_err(FactoryError::Esp)?;
|
||||
FreeRtos::delay_ms(10);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) fn main_app_launch(led_tx: &mut TxRmtDriver) -> Result<(), FactoryError> {
|
||||
neopixel(WHITE, led_tx).map_err(|e| FactoryError::EspError(e))?;
|
||||
neopixel(WHITE, led_tx).map_err(FactoryError::Esp)?;
|
||||
FreeRtos::delay_ms(10);
|
||||
Ok(())
|
||||
}
|
||||
@@ -48,7 +48,7 @@ fn ns(nanos: u64) -> Duration {
|
||||
Duration::from_nanos(nanos)
|
||||
}
|
||||
|
||||
fn neopixel(rgb: RGB, tx: &mut TxRmtDriver) -> Result<(), EspError> {
|
||||
fn neopixel(rgb: Rgb, tx: &mut TxRmtDriver) -> Result<(), EspError> {
|
||||
// e.g. rgb: (1,2,4)
|
||||
// G R B
|
||||
// 7 0 7 0 7 0
|
||||
|
||||
@@ -15,9 +15,9 @@ use esp_println::println;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub(crate) enum FactoryError {
|
||||
SdCardError(Error<SdCardError>),
|
||||
OtaError(EspError),
|
||||
EspError(EspError),
|
||||
SdCard(Error<SdCardError>),
|
||||
Ota(EspError),
|
||||
Esp(EspError),
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
@@ -52,7 +52,7 @@ fn main() -> Result<(), FactoryError> {
|
||||
|
||||
fn assign_peripherals() -> Result<(sdcard::Peripherals, led::Peripherals), FactoryError> {
|
||||
// this function here must be called only once
|
||||
let peripherals = Peripherals::take().map_err(|e| FactoryError::EspError(e))?;
|
||||
let peripherals = Peripherals::take().map_err(FactoryError::Esp)?;
|
||||
let sd_card_peripherals = sdcard::Peripherals {
|
||||
spi: peripherals.spi2,
|
||||
sck: peripherals.pins.gpio6,
|
||||
|
||||
@@ -13,14 +13,14 @@ const BUFFER_LEN: usize = 1024;
|
||||
pub(crate) fn update_present(volume_mgr: &mut Manager) -> Result<bool, FactoryError> {
|
||||
let volume0 = volume_mgr
|
||||
.get_volume(VolumeIdx(0))
|
||||
.map_err(|e| FactoryError::SdCardError(e))?;
|
||||
.map_err(FactoryError::SdCard)?;
|
||||
let root_dir = volume_mgr
|
||||
.open_root_dir(&volume0)
|
||||
.map_err(|e| FactoryError::SdCardError(e))?;
|
||||
.map_err(FactoryError::SdCard)?;
|
||||
let ret = match volume_mgr.find_directory_entry(&volume0, &root_dir, FILE) {
|
||||
Ok(_) => Ok(true),
|
||||
Err(FileNotFound) => Ok(false),
|
||||
Err(e) => Err(FactoryError::SdCardError(e)),
|
||||
Err(e) => Err(FactoryError::SdCard(e)),
|
||||
};
|
||||
volume_mgr.close_dir(&volume0, root_dir);
|
||||
ret
|
||||
@@ -29,33 +29,30 @@ pub(crate) fn update_present(volume_mgr: &mut Manager) -> Result<bool, FactoryEr
|
||||
pub(crate) fn write_update(volume_mgr: &mut Manager) -> Result<(), FactoryError> {
|
||||
let mut volume0 = volume_mgr
|
||||
.get_volume(VolumeIdx(0))
|
||||
.map_err(|e| FactoryError::SdCardError(e))?;
|
||||
.map_err(FactoryError::SdCard)?;
|
||||
let root_dir = volume_mgr
|
||||
.open_root_dir(&volume0)
|
||||
.map_err(|e| FactoryError::SdCardError(e))?;
|
||||
.map_err(FactoryError::SdCard)?;
|
||||
let mut my_file = volume_mgr
|
||||
.open_file_in_dir(&mut volume0, &root_dir, FILE, Mode::ReadOnly)
|
||||
.map_err(|e| FactoryError::SdCardError(e))?;
|
||||
.map_err(FactoryError::SdCard)?;
|
||||
|
||||
let mut ota = EspOta::new().map_err(|e| FactoryError::OtaError(e))?;
|
||||
let mut ota = ota
|
||||
.initiate_update()
|
||||
.map_err(|e| FactoryError::OtaError(e))?;
|
||||
let mut ota = EspOta::new().map_err(FactoryError::Ota)?;
|
||||
let mut ota = ota.initiate_update().map_err(FactoryError::Ota)?;
|
||||
|
||||
let mut buffer = [0u8; BUFFER_LEN];
|
||||
while !my_file.eof() {
|
||||
let r = volume_mgr
|
||||
.read(&volume0, &mut my_file, &mut buffer)
|
||||
.map_err(|e| FactoryError::SdCardError(e))?;
|
||||
ota.write(&buffer[..r])
|
||||
.map_err(|e| FactoryError::OtaError(e))?;
|
||||
.map_err(FactoryError::SdCard)?;
|
||||
ota.write(&buffer[..r]).map_err(FactoryError::Ota)?;
|
||||
}
|
||||
|
||||
ota.complete().map_err(|e| FactoryError::OtaError(e))?;
|
||||
ota.complete().map_err(FactoryError::Ota)?;
|
||||
|
||||
volume_mgr
|
||||
.close_file(&volume0, my_file)
|
||||
.map_err(|e| FactoryError::SdCardError(e))?;
|
||||
.map_err(FactoryError::SdCard)?;
|
||||
volume_mgr.close_dir(&volume0, root_dir);
|
||||
Ok(())
|
||||
}
|
||||
@@ -65,5 +62,5 @@ pub(crate) fn set_boot_main_app() -> Result<(), FactoryError> {
|
||||
let partition = esp_ota_get_next_update_partition(ptr::null());
|
||||
esp_ota_set_boot_partition(partition)
|
||||
})
|
||||
.map_err(|e| FactoryError::OtaError(e))
|
||||
.map_err(FactoryError::Ota)
|
||||
}
|
||||
|
||||
@@ -46,13 +46,13 @@ pub(crate) fn setup(peripherals: Peripherals) -> Result<Manager<'static>, Factor
|
||||
Some(peripherals.miso),
|
||||
&DriverConfig::default(),
|
||||
)
|
||||
.map_err(|e| FactoryError::EspError(e))?;
|
||||
.map_err(FactoryError::Esp)?;
|
||||
let mut spi_config = SpiConfig::new();
|
||||
spi_config.duplex = Duplex::Full;
|
||||
spi_config = spi_config.baudrate(24.MHz().into());
|
||||
let spi = SpiDeviceDriver::new(driver, Option::<Gpio10>::None, &spi_config)
|
||||
.map_err(|e| FactoryError::EspError(e))?;
|
||||
let sdmmc_cs = PinDriver::output(peripherals.cs).map_err(|e| FactoryError::EspError(e))?;
|
||||
.map_err(FactoryError::Esp)?;
|
||||
let sdmmc_cs = PinDriver::output(peripherals.cs).map_err(FactoryError::Esp)?;
|
||||
let sdcard = SdCard::new(spi, sdmmc_cs, Ets {});
|
||||
let volume_mgr = VolumeManager::new(sdcard, SdMmcClock {});
|
||||
Ok(volume_mgr)
|
||||
|
||||
Reference in New Issue
Block a user