Skip to content
Snippets Groups Projects
Commit bd497223 authored by Jake Read's avatar Jake Read
Browse files

garbaj earle code

parent ff5e3ffa
Branches
No related tags found
No related merge requests found
......@@ -60,3 +60,21 @@ Not totally sure, but I'm going to move on to try out Earle's software serial PI
[the earle pio softwareserial.cpp](https://github.com/earlephilhower/arduino-pico/blob/4c1c72c996b6a1243b0eafa956dd0eb6410e2362/cores/rp2040/SerialPIO.cpp)
So - let's try this out.
OK, my big dawg `earle` looks to have this locked down, it is werken. It's also wrapped in the arduino Serial API meaning I could use 'em in an abstracted class for P2P comms. Bless his heart, now I need to check i.e. continuity and make some measurements...
Ah, jesus, nevermind, it is catching garbage bytes... all 255's, and it's reporting new-byteness when in fact none are visible on the line.
---
### Not in Flash
I'm also noticing [this pattern](https://github.com/earlephilhower/arduino-pico/blob/4c1c72c996b6a1243b0eafa956dd0eb6410e2362/cores/rp2040/SerialPIO.cpp#L90) to do:
```cpp
void __not_in_flash_func(){}
```
Around some handlers. I wonder if this is a missing step on lots of these codes... This is discussed [in this forum post](https://forums.raspberrypi.com/viewtopic.php?t=311811) and also shows up in [the sdk here](https://github.com/raspberrypi/pico-sdk/blob/master/src/rp2_common/hardware_spi/spi.c#L84) - for fast shit. Maybe important...
Also points to a larger red flag for me about the system... maybe this is not actually the microcontroller for hardo realtime stuff...
\ No newline at end of file
#include "screen.h"
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Wire.h>
// OLED
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define X_POS 0
#define Y_POS 0
#define TXT_SIZE 1
// even for displays with i.e. "0x78" printed on the back,
// the address that works is 0x3C, IDK
#define SCREEN_ADDRESS 0x3C
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT);
// warning: is blocking, takes ~ 33ms !
void displayPrint(String msg){
display.clearDisplay();
display.setCursor(X_POS, Y_POS);
display.print(msg);
display.display();
}
void displaySetup(void){
// initialize the screen,
// oddly, SWITCHCAPVCC is the option that works even though OLED is hooked to 5V
display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS);
display.clearDisplay();
display.display();
display.setTextColor(SSD1306_WHITE);
display.setTextSize(TXT_SIZE);
display.setTextWrap(true);
display.dim(false);
displayPrint("bonjour...");
}
\ No newline at end of file
#ifndef SCREEN_H_
#define SCREEN_H_
#include <Arduino.h>
void displaySetup(void);
void displayPrint(String msg);
#endif
\ No newline at end of file
#include "screen.h"
// using an RP2040 XIAO
// with earle philhower core
// "D10" - GPIO 3
#define PIN_DEBUG 3
// on XIAO "RX" - GPIO 1
#define PIN_RX 1
#define PIO_BAUD 1000000
SerialPIO serial(SerialPIO::NOPIN, PIN_RX);
void setup(void){
pinMode(PIN_LED_B, OUTPUT);
digitalWrite(PIN_LED_B, LOW);
pinMode(PIN_DEBUG, OUTPUT);
digitalWrite(PIN_DEBUG, LOW);
// the display setup
displaySetup();
displayPrint("bonjour...");
serial.begin(PIO_BAUD);
}
uint32_t lastUpdate = 0;
uint32_t updateInterval = 200;
uint8_t expectedRx = 0;
uint32_t missCount = 0;
uint32_t catchCount = 0;
uint8_t chars[256];
void loop(void){
if(serial.available()){
// earle core throws -1 if we have an error,
int data = serial.read();
if(data < 0) {
return;
}
// count total hits
catchCount ++;
// catch data and count sequence errors
digitalWrite(PIN_DEBUG, !digitalRead(PIN_DEBUG));
chars[catchCount & 255] = data;
if(data != expectedRx){
missCount ++;
}
expectedRx = data + 1;
}
// uint8_t data = uart_rx_program_getc(pio, sm);
// digitalWrite(PIN_DEBUG, LOW);
// ...
if(lastUpdate + updateInterval < millis()){
lastUpdate = millis();
digitalWrite(PIN_LED_B, !digitalRead(PIN_LED_B));
displayPrint(String(missCount) + " / " + String(catchCount) + " \n" +
String(chars[0]) + ", " + String(chars[1]) + ", " + String(chars[2]) + ", " + String(chars[3]) + ", " + String(chars[4]) + ", " + String(chars[5]) + ", "
);
// displayPrint(spipi_print());
// displayPrint(String(rxCount) + "\n" +
// String(rxSize)
// );
}
}
......@@ -9,7 +9,7 @@
// on XIAO "TX" - GPIO 0
#define PIN_TX 0
#define PIO_BAUD 115200
#define PIO_BAUD 1000000
// the PIO, and statemachine ?
PIO pio = pio0;
......@@ -34,10 +34,12 @@ void setup(void){
uint32_t lastUpdate = 0;
uint32_t updateInterval = 200;
uint8_t seqNum = 0;
void loop(void){
digitalWrite(PIN_DEBUG, HIGH);
// blocking tx-put:
uart_tx_program_putc(pio, sm, 85);
uart_tx_program_putc(pio, sm, seqNum ++);
delayMicroseconds(200);
digitalWrite(PIN_DEBUG, LOW);
// ...
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment