Skip to content

Instantly share code, notes, and snippets.

View lupyuen's full-sized avatar
💭
Apache NuttX RTOS on Oz64 RISC-V SBC / Sophgo SG2000 SoC

Lup Yuen Lee lupyuen

💭
Apache NuttX RTOS on Oz64 RISC-V SBC / Sophgo SG2000 SoC
View GitHub Profile
Verifying my Blockstack ID is secured with the address 13pJM7w1H1E7zWp2caYhd3TedVicc8cEWo https://explorer.blockstack.org/address/13pJM7w1H1E7zWp2caYhd3TedVicc8cEWo
Verifying my Blockstack ID is secured with the address 13pJM7w1H1E7zWp2caYhd3TedVicc8cEWo https://explorer.blockstack.org/address/13pJM7w1H1E7zWp2caYhd3TedVicc8cEWo
Verifying my Blockstack ID is secured with the address 1PGgFRe5F8Q1YdepbaWU1b4hdMegLztnAf https://explorer.blockstack.org/address/1PGgFRe5F8Q1YdepbaWU1b4hdMegLztnAf
@lupyuen
lupyuen / lib.rs
Created June 18, 2018 05:16
Sample Rust program for PADI
pub extern fn main_entry() {
let mut s = Serial::new();
s.tx_string("Hello from Rust!\n");
loop {
let data = s.rx_i32();
s.tx_string("Received: ");
s.tx_i32(data);
s.tx_string("\n");
}
}
fn main() -> ! {
// Show "Hello, world!" on the debug console, which is shown in OpenOCD. "mut" means that this object is mutable, i.e. it can change.
let mut debug_out = hio::hstdout().unwrap();
writeln!(debug_out, "Hello, world!").unwrap();
// Get peripherals (clocks, flash memory, GPIO) for the STM32 Blue Pill microcontroller.
let bluepill = Peripherals::take().unwrap();
// Get the clocks from the STM32 Reset and Clock Control (RCC) and freeze the Flash Access Control Register (ACR).
let mut rcc = bluepill.RCC.constrain();
// Get GPIO Port C, which also enables the Advanced Peripheral Bus 2 (APB2) clock for Port C.
let mut gpioc = bluepill.GPIOC.split(&mut rcc.apb2);
// Use Pin PC 13 of the Blue Pill for GPIO Port C. Select Output Push/Pull mode for the pin, which is connected to our LED.
let mut led = gpioc.pc13.into_push_pull_output(&mut gpioc.crh);
...
// Loop forever.
loop {
// Output 3.3V on the LED Pin and show a message in OpenOCD console.
led.set_high();
fn main() -> ! {
// Show "Hello, world!" on the debug console, which is shown in OpenOCD. "mut" means that this object is mutable, i.e. it can change.
let mut debug_out = hio::hstdout().unwrap();
writeln!(debug_out, "Hello, world!").unwrap();
// Get peripherals (clocks, flash memory, GPIO) for the STM32 Blue Pill microcontroller.
let bluepill = Peripherals::take().unwrap();
// Get the clocks from the STM32 Reset and Clock Control (RCC) and freeze the Flash Access Control Register (ACR).
let mut rcc = bluepill.RCC.constrain();
static void sensor_setup(uint8_t display_task_id) {
// Start the sensor tasks for each sensor to read and process sensor data.
// Edit this function to add your own sensors.
// Set up the sensors and get their sensor contexts.
const int pollInterval = 500; // Poll the sensor every 500 milliseconds.
SensorContext *tempContext = setup_temp_sensor(pollInterval, display_task_id);
SensorContext *humidContext = setup_humid_sensor(pollInterval, display_task_id);
// For each sensor, create sensor tasks using the same task function, but with unique sensor context.
void sensor_task(void) {
// Background task to receive and process sensor data.
// This task will be reused by all sensors: temperature, humidity, altitude.
SensorContext *context = NULL; // Declared outside the task to prevent cross-initialisation error in C++.
MsgQ_t queue; Evt_t event; // TODO: Workaround for msg_post() in C++.
task_open(); // Start of the task. Must be matched with task_close().
for (;;) { // Run the sensor processing code forever. So the task never ends.
// This code is executed by multiple sensors. We use a global semaphore to prevent
// concurrent access to the single shared I2C Bus on Arduino Uno.
sem_wait(i2cSemaphore); // Wait until no other sensor is using the I2C Bus. Then lock the semaphore.