Skip to content

Commit 04bf756

Browse files
committed
theoretically clean version which has been tested with and without the feature
1 parent 0412a40 commit 04bf756

File tree

6 files changed

+28
-6
lines changed

6 files changed

+28
-6
lines changed

libs/cramium-hal/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,13 @@ camera-ov2640 = []
3232
camera-gc2145 = []
3333
display-sh1107 = []
3434
axp2101 = []
35+
bmp180 = []
3536
board-baosec = [
3637
"std",
3738
"camera-gc2145",
3839
"display-sh1107",
3940
"axp2101",
41+
"bmp180",
4042
"utralib/cramium-soc",
4143
"ux-api/board-baosec",
4244
] # USB form factor token
@@ -45,6 +47,7 @@ loader-baosec = [
4547
"camera-gc2145",
4648
"display-sh1107",
4749
"axp2101",
50+
"bmp180",
4851
"ux-api/loader-baosec",
4952
]
5053
kernel-baosec = ["utralib/cramium-soc"]

libs/cramium-hal/src/bmp180.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
use cramium_api::{I2cApi, I2cResult};
22

33
pub const BMP180_ADDR: u8 = 0x77;
4-
#[cfg(feature = "std")]
54
const REG_CALIB_START: u8 = 0xAA;
65
const REG_CTRL: u8 = 0xF4;
76
const REG_DATA_START: u8 = 0xF6;
87
const CMD_READ_TEMP: u8 = 0x2E;
8+
const REG_CHIP_ID: u8 = 0xD0;
99

1010
#[derive(Debug, Clone, Copy)]
1111

12-
#[allow(dead_code)]
1312
struct Bmp180Calibration {
1413
ac1: i16,
1514
ac2: i16,
@@ -29,10 +28,17 @@ pub struct Bmp180 {
2928
}
3029

3130
impl Bmp180 {
32-
#[cfg(feature = "std")]
3331
pub fn new(i2c: &mut dyn I2cApi) -> Result<Self, I2cResult> {
34-
let mut cal_buf = [0u8; 22];
32+
// dummy read to wake the chip
33+
let mut chip_id_buf = [0u8; 1];
34+
match i2c.i2c_read(BMP180_ADDR, REG_CHIP_ID, &mut chip_id_buf, true) {
35+
Ok(I2cResult::Ack(_)) => (),
36+
Ok(I2cResult::Nack) => (),
37+
Ok(other) => return Err(other),
38+
Err(_) => return Err(I2cResult::InternalError),
39+
}
3540

41+
let mut cal_buf = [0u8; 22];
3642
match i2c.i2c_read(BMP180_ADDR, REG_CALIB_START, &mut cal_buf, true) {
3743
Ok(i2c_result) => match i2c_result {
3844
I2cResult::Ack(_) => (),

libs/cramium-hal/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
pub mod debug;
66
#[cfg(feature = "axp2101")]
77
pub mod axp2101;
8+
#[cfg(feature = "bmp180")]
89
pub mod bmp180;
910
pub mod board;
1011
#[cfg(feature = "camera-gc2145")]

services/bao-console/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ hosted-baosec = [
4949
"pddb/hosted-baosec",
5050
"cramium-hal/hosted-baosec",
5151
]
52+
bmp180 = [
53+
"cramium-hal/bmp180",
54+
"cram-hal-service",
55+
]
5256
usb = []
5357
battery-readout = []
5458
with-pddb = []

services/bao-console/src/cmds/test.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
use String;
2-
use cram_hal_service::I2c;
3-
use cramium_hal::bmp180::Bmp180;
42

53
use crate::{CommonEnv, ShellCmdApi};
64

@@ -15,13 +13,22 @@ impl<'a> ShellCmdApi<'a> for Test {
1513
fn process(&mut self, args: String, _env: &mut CommonEnv) -> Result<Option<String>, xous::Error> {
1614
use core::fmt::Write;
1715
let mut ret = String::new();
16+
17+
#[allow(unused_variables)]
1818
let helpstring = "Test commands. See code for options.";
1919

20+
#[cfg(feature = "bmp180")]
21+
let helpstring = "Usage:
22+
temp - reads temperature from bmp180.";
23+
2024
let mut tokens = args.split(' ');
2125

2226
if let Some(sub_cmd) = tokens.next() {
2327
match sub_cmd {
28+
#[cfg(feature = "bmp180")]
2429
"temp" => {
30+
use cram_hal_service::I2c;
31+
use cramium_hal::bmp180::Bmp180;
2532
let mut i2c = I2c::new();
2633

2734
match Bmp180::new(&mut i2c) {

services/cram-hal-service/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ rawserial = []
4545
pinger = []
4646
swap = []
4747
mpw = ["cramium-hal/mpw"]
48+
bmp180 = ["cramium-hal/bmp180"]
4849
board-baosec = ["cramium-hal/board-baosec"]
4950
board-baosor = ["cramium-hal/board-baosor"]
5051
board-dabao = ["cramium-hal/board-dabao"]

0 commit comments

Comments
 (0)