Skip to content

Commit

Permalink
Introduced similar core effect as in rust issue #109000.
Browse files Browse the repository at this point in the history
  • Loading branch information
fvilante committed Aug 1, 2023
1 parent 80afd32 commit a472b1a
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 100 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions bare_metal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ edition = "2021"


[dependencies]
#noble-secp256k1 = { git = "https://github.com/xphoniex/noble-secp256k1-rs", default-features = false, features = ["8-bit"] }
hmac-sha256 = { version = "1.1.6", default-features = false, features = ["opt_size"] }

cross_platform = { path = "../cross_platform" }
# ruduino "default-features = false" meaning => to disable the dependency of avr-std-stub inside ruduino which implements a default panic_handler.
#We want to abort the use of this handler, because we want our own panic_handler.
Expand Down
126 changes: 26 additions & 100 deletions bare_metal/src/app.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use crate::board::front_panel::FrontPanel;
use crate::board::keyboard::Keyboard;
use crate::board::keypad::KeyCode;
use crate::board::lcd::driver::print_u8_in_hex;
use crate::board::peripherals::Peripherals;
use crate::board::peripherals::PeripheralsAvrHardware;
use crate::geometry::point::Point;
use crate::menu::model::DataModel;
use crate::menu::screen_buffer;
use crate::menu::screen_buffer::ScreenBuffer;
use crate::menu::widget::execucao::MenuExecucaoControler;
use crate::menu::widget::main_menu::MainMenu;
Expand All @@ -13,122 +15,46 @@ use crate::menu::widget::splash::Splash;
use crate::menu::widget::submenu_programa::menu_programa_controler::MenuProgramaControler;
use crate::menu::widget::submenu_programa::spec::{MenuProgramaAreanaSelector, MenuProgramaArena};
use crate::menu::widget::widget::Widget;
use crate::microcontroler::delay;
use crate::microcontroler::delay::delay_ms;
use crate::microcontroler::timer::now;
use crate::microcontroler::{serial, timer};
use cross_platform::protocol::datalink::datalink::Datalink;
use cross_platform::protocol::transport::channel::Channel;
use cross_platform::protocol::transport::transport_layer::cmpp_value::MechanicalProperties;
use cross_platform::protocol::transport::transport_layer::TransportLayer;
use cross_platform::utils::numerical::convert_u8_to_str_hex;

/// TODO: Implement user interaction with the signal emitted
fn emit_print_go_signal(transport: &TransportLayer) {
match transport.print_go() {
Ok(_status) => {
// TODO: Inform user that a print signal was successful sent to cmpp board
}
Err(_error) => {
// TODO: Inform user what kind of error happened
}
}
}

/// TODO: Make this a type
type Baudrate = u32;

/// High-level cmpp driver
///
/// Represents an entire Cmpp Axis System, including unit of measurement convertion
struct CmppAxis {
mechanical_properties: MechanicalProperties,
baudrate: Baudrate,
channel: Channel,
datalink: Datalink,
}

impl CmppAxis {
pub fn new(
baudrate: u32,
channel: Channel,
timeout_ms: u16,
mechanical_properties: MechanicalProperties,
) -> Self {
// set callbacks
fn now__() -> u16 {
timer::now() as u16
}
fn try_rx() -> Result<Option<u8>, ()> {
Ok(serial::try_receive())
}
fn try_tx(byte: u8) -> Option<()> {
serial::try_transmit(byte).ok()
}
// instantiation
let datalink = Datalink {
channel,
now: now__,
timeout_ms,
try_rx,
try_tx,
debug_reception: None,
};
Self {
mechanical_properties,
baudrate,
channel,
datalink,
}
}

fn get_transport_layer(&self) -> TransportLayer {
let transport = TransportLayer::new(&self.datalink, self.mechanical_properties);
transport
fn print_hex(lcd_: &mut ScreenBuffer, data: &[u8]) {
for byte in data.into_iter() {
let (high, low) = convert_u8_to_str_hex(byte.clone());
lcd_.print_char(high);
lcd_.print_char(low);
}
}

/// Entry point of the main application
pub fn run() -> ! {
// /////////////////////////////////////////////////////////////////////
// Initialize system
// ////////////////////////////////////////////////////////////////////
// Serial port
serial::init(2400);
let peripherals = PeripheralsAvrHardware::new();

// ////////////////////////////////////////
// Start main data storage
// ////////////////////////////////////////
//
let mut data_model = DataModel::new();
data_model.load_from_eeprom();
// lcd display buffer
let mut screen_buffer = peripherals.get_screen_buffer();

// ////////////////////////////////////////
// initialize peripherals
// ////////////////////////////////////////
//
loop {
screen_buffer.clear();
let h = hmac_sha256::HMAC::mac(b"hello", b"key");
print_hex(&mut screen_buffer, &h);
screen_buffer.render();

// Serial port
// TODO: Abstract and Improve readability of this initialization
const B2400_CODE: u8 = 0;
let baudrate_code = data_model
.configuracao_do_equipamento
.velocidade_de_comunicacao
.get()
.get_current();
let baudrate = if baudrate_code == B2400_CODE {
2400
} else {
9600
};
serial::init(baudrate);
delay_ms(1000);

// other peripherals
let peripherals = PeripheralsAvrHardware::new();
let mut front_panel = peripherals.get_front_panel();
let mut keyboard = peripherals.get_keyboard();
let mut screen_buffer = peripherals.get_screen_buffer();
screen_buffer.clear();
let h = hmac_sha256::Hash::hash(b"hello");
print_hex(&mut screen_buffer, &h);
screen_buffer.render();

screen_buffer.clear();
let text = "Juca Chaves";
for each in text.chars() {
screen_buffer.print_char(each);
delay_ms(1000);
}
screen_buffer.render();
loop {}
}

0 comments on commit a472b1a

Please sign in to comment.