9names / bl702-hal

Rust Embedded HAL for Boufallo BL702 microcontroller
MIT License
10 stars 4 forks source link

spi: port from bl602 and add lcd example for m0sense #10

Closed mattthebaker closed 1 year ago

mattthebaker commented 1 year ago

Signed-off-by: Matt Baker baker.matt.j@gmail.com

First pass to add SPI.

LCD example is ported from st7735-lcd to test the SPI/LCD on m0sense, though I'm not sure it should be committed to this repo or possibly the lcd library instead.

The miso/mosi needed to be swapped to the default location for m0sense for the relevant pins. Does the XT-ZB1 dev board need the swapped configuration? If so gpio.rs may need a way to switch it on and off.

I barely know what I'm doing in Rust so hopefully it isn't too rough.

9names commented 1 year ago

Did this work for you? It seems to only work for me if I've just run another LCD program, otherwise I get a blank screen. Or inverted colors. I tested out using mipidsi instead, and that seemed to work consistently - maybe it's just the display driver that's not working?

I put my test code in a gist, it builds on top of the code from your branch - could you test out this version? I updated your code to work with a newer version of embedded-graphics as since I needed it for my example. And I needed to add a DelayMs impl so I added a few more of those too.

https://gist.github.com/9names/4d8748d14f3417509858566abbb6663b

9names commented 1 year ago

The miso/mosi needed to be swapped to the default location for m0sense for the relevant pins. Does the XT-ZB1 dev board need the swapped configuration? If so gpio.rs may need a way to switch it on and off.

The datasheet has miso on GPIO_29 and mosi on GPIO_24 as you've used them - so your updates are correct. It does make me wonder if I've transposed all the reset of them...

9names commented 1 year ago

LCD example is ported from st7735-lcd to test the SPI/LCD on m0sense, though I'm not sure it should be committed to this repo or possibly the lcd library instead.

The example belongs here, not in the upstream repo. They don't want to have to maintain versions for every chip that exists.

mattthebaker commented 1 year ago

The original code I checked in did work for me. I tested on 2 units and power cycled to make sure it worked when coming up fresh.

The lcd_mipi.rs from the gist also works for me, but the graphic is shifted with part of it cut off.

The lcd.rs changes from the gist cause the graphic to have inverted or unusual colors. I changed the ImageRaw line back to this:

let image_raw: ImageRawLE<Rgb565> = ImageRawLE::new(include_bytes!("../assets/ferris.raw"), 86);

The colors are normal now, but there is what looks like a single column and row of noise at bottom/right.

The datasheet has miso on GPIO_29 and mosi on GPIO_24 as you've used them - so your updates are correct. It does make me wonder if I've transposed all the reset of them...

They're all swapped compared to the "Default" setting per the datasheet, but the original code copied from bl602_hal had the "Swap" bit set so the pin array was valid. Seems the XT-BL and m0sense use the default so it's maybe okay to switch the pin array back to the default until more boards come out that need a dynamic setting.

mattthebaker commented 1 year ago

If you're still seeing different behavior and its relevant, the marking on my LCDs is Wisevision N096-1608THBIG09-C08 W2208011113

9names commented 1 year ago

Mine has the same first two lines and W2209049042. I think it's very likely to be the same screen model.

9names commented 1 year ago

Rebuilt it on a Windows PC (in case it was something else on my system causing problems). Same issue. Displayed correctly once (because my program was loaded previously). Just a black screen after that.

Anyway: not super important. The SPI driver port works, which is the main thing. Can I get you to move the LCD + embedded graphics dependencies into [dev-dependencies] in Cargo.toml, then we can merge and deal with issues with the example later.

9names commented 1 year ago

I updated my gist with the correct offsets for mipi_dsi. Tested it with a reduced version of https://en.wikipedia.org/wiki/Rainbow#/media/File:Double-alaskan-rainbow.jpg to ensure that i was getting correct colors. Double-alaskan-rainbow_160x80_left Looks fine I guess, though I'm suspicious of the red of her coat showing up a little yellow. It is exceptionally hard to photograph little LCDs. m0sense_screen Double-alaskan-rainbow_160x80_left.zip

Raw image is in the zip, if you want to test

mattthebaker commented 1 year ago

Made the dependency change, along with shuffling all of the MOSI/MISO pin mappings to match the chip defaults without swap.

I'm not sure why CI failed, nothing related to dependencies really changed.

Your updated mipi-dsi example works for ferris and the alaska image, and the colors look very good on my screen. No issue with blanking on restart.

9names commented 1 year ago

The riscv folks yanked a release due to a major bug, we should update to the latest release. PR looks good to me though, breakage isn't your fault.

mattthebaker commented 1 year ago

Sounds important.

I'm working on hooks for the ADC too, and probably I2C later. Want to try making a dual mode (acoustic + vibration) tuner for lowish (<250hz) frequencies. Wish the accelerometer was on the SPI bus for bandwidth.

9names commented 1 year ago

I'll clean up the riscv breakage in a new branch. Thanks for this PR, looking forward to the ADC/I2C work :+1: