1
0
forked from M-Labs/kirdy

firmware: Add cmd to get hw_rev

This commit is contained in:
linuswck 2024-09-03 16:30:51 +08:00
parent 6782cda790
commit c5826876a6
4 changed files with 39 additions and 5 deletions

View File

@ -9,7 +9,8 @@ use uom::si::{electric_current::{ampere, milliampere},
f32::ElectricCurrent};
use super::{gpio, sys_timer, usb};
use crate::{device::flash_store::{self, FlashStore},
use crate::{device::{flash_store::{self, FlashStore},
hw_rev::HWRev},
laser_diode::{laser_diode::LdDrive, ld_ctrl::*},
net::net::{IpSettings, ServerHandle},
thermostat::{max1968::MAX1968, thermostat::Thermostat},
@ -23,7 +24,7 @@ const WATCHDOG_PERIOD: u32 = 30000;
pub fn bootup(
mut core_perif: CorePeripherals,
perif: Peripherals,
) -> (IndependentWatchdog, FlashStore, LdDrive, Thermostat) {
) -> (IndependentWatchdog, FlashStore, HWRev, LdDrive, Thermostat) {
core_perif.SCB.enable_icache();
core_perif.SCB.enable_dcache(&mut core_perif.CPUID);
@ -119,5 +120,5 @@ pub fn bootup(
info!("Kirdy setup complete");
(wd, flash_store, laser, thermostat)
(wd, flash_store, hw_rev, laser, thermostat)
}

View File

@ -1,4 +1,6 @@
use crc::{Crc, CRC_24_BLE};
use miniconf::Tree;
use serde::{Deserialize, Serialize};
use stm32f4xx_hal::{gpio::{Input, PE10, PE11, PE8, PE9},
signature};
@ -11,6 +13,7 @@ pub struct HwRevPins {
pub h3: PE11<Input>,
}
#[derive(Deserialize, Serialize, Copy, Clone, Debug, Tree)]
pub struct HWRev {
pub major: u8,
pub minor: u8,

View File

@ -64,7 +64,7 @@ fn main() -> ! {
let core_perif = CorePeripherals::take().unwrap();
let perif = Peripherals::take().unwrap();
let (mut wd, mut flash_store, mut laser, mut thermostat) = bootup(core_perif, perif);
let (mut wd, mut flash_store, mut hw_rev, mut laser, mut thermostat) = bootup(core_perif, perif);
let mut device_settings = DeviceSettings {
ip_settings: IpSettings::default(),
@ -195,6 +195,7 @@ fn main() -> ! {
eth_data_buffer,
bytes,
&mut socket,
&mut hw_rev,
&mut laser,
&mut thermostat,
&mut state,

View File

@ -10,7 +10,7 @@ use uom::si::{electric_current::{ampere, ElectricCurrent},
electrical_resistance::{ohm, ElectricalResistance},
power::{watt, Power}};
use crate::{device::{dfu, sys_timer},
use crate::{device::{dfu, hw_rev::HWRev, sys_timer},
laser_diode::{laser_diode::{LdDrive, LdSettingsSummary, StatusReport as LdStatusReport},
pd_mon_params::{self, ResponsitivityUnit}},
net::net,
@ -26,6 +26,7 @@ pub enum ResponseEnum {
Reserved,
Settings,
Report,
HwRev,
Acknowledge,
InvalidDatatype,
InvalidCmd,
@ -59,6 +60,7 @@ pub struct ResponseObj<'a> {
enum DeviceCmd {
#[default]
Reserved,
GetHwRev,
SetIPSettings,
SetActiveReportMode,
SetPdFinGain,
@ -173,6 +175,17 @@ pub struct SettingsSummaryObj {
json: SettingsSummary,
}
#[derive(Deserialize, Serialize, Copy, Clone, Debug, Tree)]
pub struct HwRevType {
msg_type: ResponseEnum,
hw_rev: HWRev,
}
#[derive(Deserialize, Serialize, Copy, Clone, Debug, Tree)]
pub struct HwRevObj {
json: HwRevType,
}
pub fn send_response(buffer: &mut [u8], msg_type: ResponseEnum, msg: MsgType, socket: &mut SocketHandle) {
let response = ResponseObj {
json: Response {
@ -227,6 +240,18 @@ pub fn send_status_report(
net::eth_send(buffer, num_bytes, *socket);
}
pub fn send_hw_rev(buffer: &mut [u8], hw_rev_o: &mut HWRev, socket: &mut SocketHandle) {
let hw_rev = HwRevObj {
json: HwRevType {
msg_type: ResponseEnum::HwRev,
hw_rev: *hw_rev_o,
},
};
let mut num_bytes = hw_rev.get_json("/json", buffer).unwrap();
buffer[num_bytes] = b'\n';
num_bytes += 1;
net::eth_send(buffer, num_bytes, *socket);
}
// Use a minimal struct for high speed cmd ctrl to reduce processing overhead
#[derive(Deserialize, Serialize, Copy, Clone, Debug, Default, Tree)]
pub struct TecSetICmdJson {
@ -245,6 +270,7 @@ pub fn execute_cmd(
buffer: &mut [u8],
buffer_size: usize,
socket: &mut SocketHandle,
hw_rev: &mut HWRev,
laser: &mut LdDrive,
thermostat: &mut Thermostat,
state: &mut State,
@ -349,6 +375,9 @@ pub fn execute_cmd(
);
}
},
Some(DeviceCmd::GetHwRev) => {
send_hw_rev(buffer, hw_rev, socket);
}
Some(DeviceCmd::GetStatusReport) => {
send_status_report(buffer, laser, thermostat, socket);
}