Skip to content

Commit

Permalink
Merge branch 'ferrous-systems:main' into fix/docker-ci
Browse files Browse the repository at this point in the history
  • Loading branch information
SergioGasquez authored Nov 29, 2022
2 parents 24d269c + c90d9cc commit 8eac54b
Show file tree
Hide file tree
Showing 111 changed files with 25,239 additions and 915 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/dockerimage.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
---
name: Docker Image

on:
push:
branches: [main]
on:
push: {}
pull_request:
branches: [main]
paths-ignore:
- "book/"
- "book/**"

jobs:
# To avoid uploading the Docker image to a registry yet
Expand All @@ -26,4 +26,4 @@ jobs:
- name: Test code examples in Docker image
run: |
docker run --mount type=bind,source="$(pwd)",target=/workspace,consistency=cached \
--rm esp:latest /bin/bash /workspace/.devcontainer/test.sh
--rm esp:latest /bin/bash /workspace/.devcontainer/test.sh
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ There is:
* [`esp32-c3-dkc02-bsc`](./common/lib/esp32-c3-dkc02-bsc) - Board-Support for the ESP32-C3-DKC02
* [`get-uuid`](./common/lib/get-uuid) - provides a compile-time generated UUID
* [`mqtt-messages`](./common/lib/mqtt-messages) - MQTT helper functions
* [`imc42670p`](./common/lib/imc42670p) - basic sensor driver
* [`icm42670p`](./common/lib/icm42670p) - basic sensor driver
* Some extra bits:
* [`mqtt-python-client`](./extra/mqtt-python-client) A Python MQTT client, for testing

Expand Down
4 changes: 2 additions & 2 deletions advanced/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ Folders are listed in alphabetical order, not in the order they are taught in th
`button-interrupt/solution/src/main_led.rs` contains the solution for the second step of the exercise.
## I2C Driver exercise (WIP)

`i2c-driver/exercise/src/imc42670p.rs` will be gap text of a very basic i2c IMU sensor driver. The task is to complete the file, so that running `main.rs` will log the device ID of the driver. The this gap text driver is based on the version of the same name that lives in common, but provides a little bit more functionality.
`i2c-driver/exercise/src/icm42670p.rs` will be gap text of a very basic i2c IMU sensor driver. The task is to complete the file, so that running `main.rs` will log the device ID of the driver. The this gap text driver is based on the version of the same name that lives in common, but provides a little bit more functionality.

`i2c-driver/exercise/src/main.rs` will contain working code. Running it without modifying the driver file will yield errors.

`i2c-driver/solution/src/imc42670p.rs` provides a solution to the task.
`i2c-driver/solution/src/icm42670p.rs` provides a solution to the task.

## I2C Sensor Reading Exercise (WIP)

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,8 @@ native = ["esp-idf-sys/native"]
[dependencies]
esp-idf-sys = { version = "=0.31.5", features = ["binstart"] }
anyhow = "1"
esp32-c3-dkc02-bsc = { path = "../../../common/lib/esp32-c3-dkc02-bsc" }
esp32-c3-dkc02-bsc = { path = "../../common/lib/esp32-c3-dkc02-bsc" }

[build-dependencies]
embuild = "0.28"
anyhow = "1"

[patch.crates-io]
riscv = { git = "https://github.com/rust-embedded/riscv", rev = "396fb9b"}
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@

use std::ptr;

// If using the `binstart` feature of `esp-idf-sys`, always keep this module imported (`self as _`)
use esp_idf_sys::{
self as _, c_types::c_void, esp, gpio_config, gpio_config_t, gpio_install_isr_service,
c_types::c_void, esp, gpio_config, gpio_config_t, gpio_install_isr_service,
gpio_int_type_t_GPIO_INTR_POSEDGE, gpio_isr_handler_add, gpio_mode_t_GPIO_MODE_INPUT,
xQueueGenericCreate, xQueueGiveFromISR, xQueueReceive, QueueHandle_t,ESP_INTR_FLAG_IRAM,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ use std::ptr;
use esp32_c3_dkc02_bsc as bsc;
use bsc::led::{RGB8, WS2812RMT};

// If using the `binstart` feature of `esp-idf-sys`, always keep this module imported (`self as _`)
use esp_idf_sys::{
self as _, c_types::c_void, esp, gpio_config, gpio_config_t, gpio_install_isr_service,
c_types::c_void, esp, gpio_config, gpio_config_t, gpio_install_isr_service,
gpio_int_type_t_GPIO_INTR_POSEDGE, gpio_isr_handler_add, gpio_mode_t_GPIO_MODE_INPUT,
xQueueGenericCreate, xQueueGiveFromISR, xQueueReceive, QueueHandle_t,ESP_INTR_FLAG_IRAM, esp_random,
};
Expand Down
5 changes: 0 additions & 5 deletions advanced/button-interrupt/solution/.gitignore

This file was deleted.

29 changes: 0 additions & 29 deletions advanced/button-interrupt/solution/Cargo.toml

This file was deleted.

1 change: 0 additions & 1 deletion advanced/button-interrupt/solution/README.md

This file was deleted.

10 changes: 0 additions & 10 deletions advanced/button-interrupt/solution/sdkconfig.defaults

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
// https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/freertos.html
use std::ptr;

// If using the `binstart` feature of `esp-idf-sys`, always keep this module imported (`self as _`)
use esp_idf_sys::{
self as _, c_types::c_void, esp, gpio_config, gpio_config_t, gpio_install_isr_service,
c_types::c_void, esp, gpio_config, gpio_config_t, gpio_install_isr_service,
gpio_int_type_t_GPIO_INTR_POSEDGE, gpio_isr_handler_add, gpio_mode_t_GPIO_MODE_INPUT,
xQueueGenericCreate, xQueueGiveFromISR, xQueueReceive, QueueHandle_t,ESP_INTR_FLAG_IRAM, esp_random,
};
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,12 @@ default = ["native"]
native = ["esp-idf-sys/native"]

[dependencies]
esp-idf-sys = { version = "0.31", features = ["binstart"] }
esp-idf-hal = "0.35.1"
esp-idf-sys = { version = "=0.31.5", features = ["binstart"] }
esp-idf-hal = "=0.38"
anyhow = "1"
embedded-hal = "0.2.7"


[build-dependencies]
embuild = "0.28"
anyhow = "1"

[patch.crates-io]
riscv = { git = "https://github.com/rust-embedded/riscv", rev = "396fb9b"}
File renamed without changes.
File renamed without changes.
4 changes: 0 additions & 4 deletions advanced/i2c-driver/solution/src/lib.rs

This file was deleted.

78 changes: 78 additions & 0 deletions advanced/i2c-driver/src/icm42670p.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#![deny(unsafe_code)]

use embedded_hal::blocking::i2c;
use core::marker::PhantomData;

/// ICM42670P device driver, represented by a struct with 2 fields.
/// Datasheet: https://3cfeqx1hf82y3xcoull08ihx-wpengine.netdna-ssl.com/wp-content/uploads/2021/07/DS-000451-ICM-42670-P-v1.0.pdf
#[derive(Debug)]
pub struct ICM42670P<I2C> {
// The concrete I²C device implementation.
// TODO! field 1
// Device address
// TODO! field 2
// remove the following line as soon as the I2C parameter is used.
rec_type: PhantomData<I2C>,
}

// See Table 3.3.2 in Documentation
/// Contains the possible variants of the devices addesses as binary numbers.
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum DeviceAddr {
AD0, // add address
AD1, // add address
}

// impl block with methods
impl<I2C, E>ICM42670P<I2C>
where
// this defines which error messages will be used
I2C: i2c::WriteRead<Error = E> + i2c::Write<Error = E>,
{
/// Creates a new instance of the sensor, taking ownership of the i2c peripheral.
pub fn new(i2c: I2C, address: DeviceAddr) -> Result<Self, E> {
// instantiates the ICM42670P struct
// returns the struct as Ok value
todo!();
}

/// Returns the device's ID `0x67
//(if it doesn't, something is amiss)
// Public method that can be accessed from outside this file.
pub fn read_device_id_register(&mut self) -> Result<u8, E> {
// reads the Device ID register
todo!();
}

/// Writes into a register
// This method is not public as it is only needed inside this file.
#[allow(unused)]
fn write_register(&mut self, register: Register, value: u8) -> Result<(), E> {
// value that will be written as u8
// i2c write
todo!();
}

/// Reads a register using a `write_read` method.
// This method is not public as it is only needed inside this file.
fn read_register(&mut self, register: Register) -> Result<u8, E> {
// buffer for values
// i2c write_read
// return u8 from le bytes
todo!();
}
}

// See Table 14.1 in documentation
/// This enum represents the device's registers
#[derive(Clone, Copy)]
pub enum Register {
// WhoAmI Register
}

impl Register {
fn address(&self) -> u8 {
// Returns Register as u8
todo!();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,45 @@

use embedded_hal::blocking::i2c;

/// IMC42670P device driver.
/// ICM42670P device driver.
/// Datasheet: https://3cfeqx1hf82y3xcoull08ihx-wpengine.netdna-ssl.com/wp-content/uploads/2021/07/DS-000451-ICM-42670-P-v1.0.pdf
#[derive(Debug)]
pub struct IMC42670P<I2C> {
/// The concrete I²C device implementation.
pub struct ICM42670P<I2C> {
// The concrete I²C device implementation.
i2c: I2C,

/// Device address
address: SlaveAddr,
// Device address
address: DeviceAddr,
}

// see Table 3.3.2
// See Table 3.3.2 in Documentation
/// Contains the possible variants of the devices addesses as binary numbers.
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum SlaveAddr {

pub enum DeviceAddr {
/// 0x68
AD0 = 0b110_1000,
/// 0x69
AD1 = 0b110_1001,
}

impl<I2C, E>IMC42670P<I2C>
impl<I2C, E>ICM42670P<I2C>
where
I2C: i2c::WriteRead<Error = E> + i2c::Write<Error = E>,
{
/// Creates a new instance of the sensor, taking ownership of the i2c peripheral
pub fn new(i2c: I2C, address: SlaveAddr) -> Result<Self, E> {

let imc42670p = IMC42670P { i2c, address };

Ok(imc42670p)
/// Creates a new instance of the sensor, taking ownership of the i2c peripheral.
pub fn new(i2c: I2C, address: DeviceAddr) -> Result<Self, E> {
Ok(Self { i2c, address })
}

/// Should return `0x67 (if it doesn't, something is amiss)
/// Public method that can be accessed from outside this file
pub fn read_device_id_register(&mut self) -> Result<u16, E> {
/// Returns the device's ID `0x67
//(if it doesn't, something is amiss)
// Public method that can be accessed from outside this file.
pub fn read_device_id_register(&mut self) -> Result<u8, E> {
self.read_register(Register::WhoAmI)
}

/// Writes into a register
/// This method is not public as it is only needed inside this file
// This method is not public as it is only needed inside this file.
#[allow(unused)]
fn write_register(&mut self, register: Register, value: u8) -> Result<(), E> {
let byte = value as u8;
Expand All @@ -49,16 +49,17 @@ where
}

/// Reads a register using a `write_read` method.
/// this method is not public as it is only needed inside this file
fn read_register(&mut self, register: Register) -> Result<u16, E> {
let mut data = [0; 2];
// This method is not public as it is only needed inside this file.
fn read_register(&mut self, register: Register) -> Result<u8, E> {
let mut data = [0];
self.i2c
.write_read(self.address as u8, &[register.address()], &mut data)?;
Ok(u16::from_le_bytes(data))
Ok(u8::from_le_bytes(data))
}
}

// Table 14.1
// See Table 14.1 in documentation
/// This enum represents the device's registers
#[derive(Clone, Copy)]
pub enum Register {
WhoAmI = 0x75,
Expand Down
11 changes: 11 additions & 0 deletions advanced/i2c-driver/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#![deny(unsafe_code)]
#![no_std]

// pub mod icm42670p;


// uncomment the following line to run the solution, check lib.rs for further instructions
// pub mod icm42670p_solution;

// comment out the following line to run the exercise, check lib.rs for further instructions
pub mod icm42670p;
Loading

0 comments on commit 8eac54b

Please sign in to comment.