Files
lowobservable.coax/interface2/firmware/include/NewCoax.h
Andrew Kay 05438f2c60 hacking
2020-08-25 19:31:43 -05:00

58 lines
1.5 KiB
C++

// Copyright (c) 2019, Andrew Kay
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#pragma once
#define ERROR_RX_RECEIVER_ACTIVE -5
#define ERROR_RX_TIMEOUT -2
#define ERROR_RX_OVERFLOW -3
class NewCoaxDataBus;
enum NewCoaxReceiverState { Disabled, Idle, Receiving, Received };
class NewCoaxReceiver
{
public:
NewCoaxReceiver(NewCoaxDataBus &dataBus) : _dataBus(dataBus) { };
void begin();
void enable();
void disable();
void reset();
void activeInterrupt();
void dataAvailableInterrupt();
void errorInterrupt();
private:
NewCoaxDataBus &_dataBus;
volatile NewCoaxReceiverState _state = Disabled;
uint16_t read();
};
class NewCoaxDataBus
{
public:
void setMode(uint8_t mode, bool force);
uint16_t read();
void write(uint16_t word);
private:
int _mode = -1;
uint16_t encode(uint16_t word);
uint16_t decode(uint16_t word);
};