WarpTwin
Documentation for WarpTwin models and classes.
Loading...
Searching...
No Matches
Platform.h
Go to the documentation of this file.
1/******************************************************************************
2* Copyright (c) ATTX INC 2025. All Rights Reserved.
3*
4* This software and associated documentation (the "Software") are the
5* proprietary and confidential information of ATTX, INC. The Software is
6* furnished under a license agreement between ATTX and the user organization
7* This software and associated documentation (the "Software") are the
8* proprietary and confidential information of ATTX, INC. The Software is
9* furnished under a license agreement between ATTX and the user organization
10* and may be used or copied only in accordance with the terms of the agreement.
11* Refer to 'license/attx_license.adoc' for standard license terms.
12*
13* EXPORT CONTROL NOTICE: THIS SOFTWARE MAY INCLUDE CONTENT CONTROLLED UNDER THE
14* INTERNATIONAL TRAFFIC IN ARMS REGULATIONS (ITAR) OR THE EXPORT ADMINISTRATION
15* REGULATIONS (EAR99). No part of the Software may be used, reproduced, or
16* transmitted in any form or by any means, for any purpose, without the express
17* INTERNATIONAL TRAFFIC IN ARMS REGULATIONS (ITAR) OR THE EXPORT ADMINISTRATION
18* REGULATIONS (EAR99). No part of the Software may be used, reproduced, or
19* transmitted in any form or by any means, for any purpose, without the express
20* written permission of ATTX, INC.
21******************************************************************************/
22/*
23HAL header file
24
25Author: Alex Reynolds
26*/
27#ifndef FLIGHT_PLATFORM_H
28#define FLIGHT_PLATFORM_H
29
30#include "types.h"
31
33
34namespace warpos {
35
40 uint8 bank; // The bank on which to set the pin
41 uint32 pin; // The pin to set
42 uint32 mode; // Operating mode for the pin
43 uint32 speed; // Speed for output pins (not always used)
44 uint32 pull; // Sets pull (up/down/no) for the selected pin
45 uint32 alternate; // Specifies peripheral connected to pins
46};
47
52 const char *device; // The device to configure SPI for
53 uint32 clock_rate; // The clock rate in Hz
54 uint8 mode; // The SPI mode to set mode to. Configuration items are same as Linux config.
55 uint8 bits_per_word; // The number of bits per SPI word. Typical is 8. Sometimes 16.
56};
57
62 const char *device; // The device to configure UART for
63 uint32 baud_rate; // The baud rate
64 int8 parity; // Parity bit config. Can be none, even, or odd
65 uint8 data_bits; // The number of bits in data. Typically 8
66 uint8 stop_bits; // The number of stop bits. 1 or 2
67};
68
73 const char *device; // The device to configure I2C for
74 uint32 clock_rate; // The clock rate in Hz
75 int timeout_ms; // Timeout in milliseconds
76};
77
82 const char* device; // The device to configure PWMs
83 uint8 channel; // Time channel to configure PWMs
84 uint32 signal_rate; // The signal rate in Hz
85 int32 fd; // File descriptor object
86 // TODO add min/max pulse width
87};
88
93 const char *device; // The device to configure the ADC interface for
94 uint16 resolution_bits; // The number of resolution bits on the ADC
95 floating_point voltage_min; // The minimum voltage in V that can be read by the ADC
96 floating_point voltage_max; // The maximum voltage in V that can be read by the ADC
97 floating_point timeout_ms; // ADC read timeout, in ms
98};
99
111class Platform {
112public:
114 virtual ~Platform() {}
115
125 virtual int16 startup() {return ERROR_BUFFER_NOT_IMPLEMENTED;}
126
130 virtual int16 setPinMode(const GpioConfig_t &config) {return ERROR_BUFFER_NOT_IMPLEMENTED;}
136 virtual int16 writePin(uint8 bank, uint32 pin, uint32 value) {return ERROR_BUFFER_NOT_IMPLEMENTED;}
142 virtual int16 readPin(uint8 bank, uint32 pin, uint32 &value) {return ERROR_BUFFER_NOT_IMPLEMENTED;}
143
147 virtual int32 openSPI(const SpiConfig_t &config) {return ERROR_BUFFER_NOT_IMPLEMENTED;}
153 virtual int16 readSPI(int32 spi_device, uint8 *buffer, uint8 size) {return ERROR_BUFFER_NOT_IMPLEMENTED;}
159 virtual int16 writeSPI(int32 spi_device, uint8 *buffer, uint8 size) {return ERROR_BUFFER_NOT_IMPLEMENTED;}
165 virtual int16 readWriteSPI(int32 spi_device, uint8 *buffer, uint8 size) {return ERROR_BUFFER_NOT_IMPLEMENTED;}
166
170 virtual int32 openSerial(const UartConfig_t &config) {return ERROR_BUFFER_NOT_IMPLEMENTED;}
176 virtual int16 writeSerial(int32 device_fd, uint8 *buffer, uint8 size) {return ERROR_BUFFER_NOT_IMPLEMENTED;}
182 virtual uint32 readSerial(int32 device_fd, uint8 *buffer, uint32 size) {return ERROR_BUFFER_NOT_IMPLEMENTED;}
186 virtual uint32 bytesReadySerial(int32 device_fd) {return ERROR_BUFFER_NOT_IMPLEMENTED;}
187
191 virtual int32 openI2C(const I2cConfig_t &config) {return ERROR_BUFFER_NOT_IMPLEMENTED;}
198 virtual int16 writeI2C(int32 i2c_fd, uint8 i2c_address, uint8 *buffer, uint8 size) {return ERROR_BUFFER_NOT_IMPLEMENTED;}
204 virtual int16 readI2C(int32 i2c_fd, uint8 i2c_address, uint8 *buffer, uint32 size) {return ERROR_BUFFER_NOT_IMPLEMENTED;}
213 virtual int16 writeI2CAddress(int32 i2c_fd, uint8 i2c_address, uint32 mem_address, uint8 *buffer, uint32 size, bool memory_16 = false) {return ERROR_BUFFER_NOT_IMPLEMENTED;}
222 virtual int16 readI2CAddress(int32 i2c_fd, uint8 i2c_address, uint32 mem_address, uint8 *buffer, uint32 size, bool memory_16 = false) {return ERROR_BUFFER_NOT_IMPLEMENTED;}
232 virtual int16 writePwm(int32 pwm_fd, uint8 channel, uint32 value) {return ERROR_BUFFER_NOT_IMPLEMENTED;}
233
238 virtual int32 openAdc(const AdcConfig_t &adc) {return ERROR_BUFFER_NOT_IMPLEMENTED;}
239
245 virtual int16 readAdc(int32 adc_fd, uint32 adc_ch_idx, floating_point &read_voltage) {return ERROR_BUFFER_NOT_IMPLEMENTED;}
246};
247}
248
249#endif
virtual int32 openSerial(const UartConfig_t &config)
Open and configture UART connection.
Definition Platform.h:170
virtual int16 setPinMode(const GpioConfig_t &config)
Set the mode for a given GPIO pin on platform.
Definition Platform.h:130
virtual int32 openAdc(const AdcConfig_t &adc)
Open an ADC device.
Definition Platform.h:238
virtual int16 writePwm(int32 pwm_fd, uint8 channel, uint32 value)
Write a buffer of data to an I2C address.
Definition Platform.h:232
virtual int16 writePin(uint8 bank, uint32 pin, uint32 value)
Write data value to a pin.
Definition Platform.h:136
virtual int16 writeSerial(int32 device_fd, uint8 *buffer, uint8 size)
Write a byte to UART.
Definition Platform.h:176
virtual ~Platform()
Definition Platform.h:114
virtual int16 writeSPI(int32 spi_device, uint8 *buffer, uint8 size)
Write a set of bytes via SPI.
Definition Platform.h:159
virtual int16 readI2C(int32 i2c_fd, uint8 i2c_address, uint8 *buffer, uint32 size)
Read a byte from I2C.
Definition Platform.h:204
virtual int16 startup()
Initialize the platform.
Definition Platform.h:125
Platform()
Definition Platform.h:113
virtual int16 readI2CAddress(int32 i2c_fd, uint8 i2c_address, uint32 mem_address, uint8 *buffer, uint32 size, bool memory_16=false)
Write a buffer of data to an I2C address.
Definition Platform.h:222
virtual uint32 bytesReadySerial(int32 device_fd)
Check number of bytes ready to read on UART.
Definition Platform.h:186
virtual int16 readSPI(int32 spi_device, uint8 *buffer, uint8 size)
Read a set of bytes via SPI.
Definition Platform.h:153
virtual uint32 readSerial(int32 device_fd, uint8 *buffer, uint32 size)
Read a byte from UART.
Definition Platform.h:182
virtual int32 openSPI(const SpiConfig_t &config)
Open and configure SPI.
Definition Platform.h:147
virtual int16 writeI2C(int32 i2c_fd, uint8 i2c_address, uint8 *buffer, uint8 size)
Write a byte to I2C.
Definition Platform.h:198
virtual int16 writeI2CAddress(int32 i2c_fd, uint8 i2c_address, uint32 mem_address, uint8 *buffer, uint32 size, bool memory_16=false)
Write a buffer of data to an I2C address.
Definition Platform.h:213
virtual int16 readWriteSPI(int32 spi_device, uint8 *buffer, uint8 size)
Write and read a set of bytes via SPI.
Definition Platform.h:165
virtual int16 readPin(uint8 bank, uint32 pin, uint32 &value)
Read data value from a pin.
Definition Platform.h:142
virtual int32 openI2C(const I2cConfig_t &config)
Open an I2C device.
Definition Platform.h:191
virtual int16 openPwmChannel(PwmConfig_t &config)
Open a PWM channel.
Definition Platform.h:226
virtual int16 readAdc(int32 adc_fd, uint32 adc_ch_idx, floating_point &read_voltage)
Read a voltage value from ADC.
Definition Platform.h:245
#define ERROR_BUFFER_NOT_IMPLEMENTED
Variable to raise an error if an appropriate buffer is not in place.
Definition clockwerkerrors.h:126
Definition DeadReckon.cpp:20
Struct type definition for ADC configuration interface.
Definition Platform.h:92
const char * device
Definition Platform.h:93
floating_point voltage_min
Definition Platform.h:95
floating_point timeout_ms
Definition Platform.h:97
floating_point voltage_max
Definition Platform.h:96
uint16 resolution_bits
Definition Platform.h:94
Struct type definition for GPIO configuration interface.
Definition Platform.h:39
uint32 pull
Definition Platform.h:44
uint32 mode
Definition Platform.h:42
uint32 pin
Definition Platform.h:41
uint32 alternate
Definition Platform.h:45
uint8 bank
Definition Platform.h:40
uint32 speed
Definition Platform.h:43
Struct type definition for I2C configuration interface.
Definition Platform.h:72
const char * device
Definition Platform.h:73
uint32 clock_rate
Definition Platform.h:74
int timeout_ms
Definition Platform.h:75
Struct type definition for PWM configuration interface.
Definition Platform.h:81
uint8 channel
Definition Platform.h:83
uint32 signal_rate
Definition Platform.h:84
int32 fd
Definition Platform.h:85
const char * device
Definition Platform.h:82
Struct type definition for SPI configuration interface.
Definition Platform.h:51
uint8 mode
Definition Platform.h:54
uint8 bits_per_word
Definition Platform.h:55
uint32 clock_rate
Definition Platform.h:53
const char * device
Definition Platform.h:52
Struct type definition for UART configuration interface.
Definition Platform.h:61
uint8 data_bits
Definition Platform.h:65
uint8 stop_bits
Definition Platform.h:66
uint32 baud_rate
Definition Platform.h:63
int8 parity
Definition Platform.h:64
const char * device
Definition Platform.h:62