smartknob/firmware/src/serial/uart_stream.h
Scott Bezek ae28d523e0
Protobuf serial protocol (#101)
- Firmware
  - Refactor all code to use a log interface rather than `Serial` directly
  - Moved platformio.ini to root, so you can load the entire repo in VS Code and still use platformio
  - Reduced graphic buffer bit depth to 8 bits (short on RAM :( )
  - Implemented threadsafe log interface in interface_task (using a queue for posting log message)
  - Created serial protocol interface and 2 implementations - plaintext (default) and protobuf (selected by sending a NULL byte)
  - Protobuf protocol is roughly the same architecture as Splitflap's:
    - PacketSerial (cobs) framing with NULL delimiters
    - CRC32 checksums for packets
    - nanopb generated code for encoding/decoding (generated firmware code is checked in, since it should change less frequently and this reduces burden to build the project from scratch)
- Software
  - Typescript example host-side code:
    - smartknobjs-proto
      - Autogenerated types/encoding/decoding protobuf code (using protobufjs)
    - smartknobjs
      - Helper library for interfacing the with smartknob via serial/protobuf. Implements basic outgoing queue (with retries and ACK checking) and message callback for responding to messages from the SmartKnob
    - example
      - Basic demo CLI app that uses smartknobjs to connect to the smartknob, send a haptic config, and print state changes and log messages to the console
2022-10-22 17:27:35 -07:00

48 lines
1.5 KiB
C++

/*
Copyright 2021 Scott Bezek and the splitflap contributors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#pragma once
#include <Arduino.h>
#include <driver/uart.h>
/**
* Implementation of an Arduino Stream for UART serial communications using the esp uart driver
* directly, rather than the Arduino HAL which has a small fixed underlying rx FIFO size and
* potentially other issues that cause dropped bytes at high speeds/bursts.
*
* This is not a full or optimized implementation; just the minimal necessary for this project.
*/
class UartStream : public Stream {
public:
UartStream();
void begin();
// Stream methods
int available() override;
int read() override;
int peek() override;
void flush() override;
// Print methods
size_t write(uint8_t b) override;
size_t write(const uint8_t *buffer, size_t size) override;
private:
const uart_port_t uart_port_ = UART_NUM_0;
};