airbourne_board.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017, James Jackson and Daniel Koch, BYU MAGICC Lab
3  *
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  *
9  * * Redistributions of source code must retain the above copyright notice, this
10  * list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright notice,
13  * this list of conditions and the following disclaimer in the documentation
14  * and/or other materials provided with the distribution.
15  *
16  * * Neither the name of the copyright holder nor the names of its
17  * contributors may be used to endorse or promote products derived from
18  * this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #ifndef ROSFLIGHT_FIRMWARE_AIRBOURNE_BOARD_H
33 #define ROSFLIGHT_FIRMWARE_AIRBOURNE_BOARD_H
34 
35 #include "M25P16.h"
37 #include "analog_pin.h"
38 #include "backup_sram.h"
39 #include "battery_monitor.h"
40 #include "board.h"
41 #include "hmc5883l.h"
42 #include "i2c.h"
43 #include "led.h"
44 #include "mb1242.h"
45 #include "mpu6000.h"
46 #include "ms4525.h"
47 #include "ms5611.h"
48 #include "pwm.h"
49 #include "rc_base.h"
50 #include "rc_ppm.h"
51 #include "rc_sbus.h"
52 #include "serial.h"
53 #include "spi.h"
54 #include "system.h"
55 #include "uart.h"
56 #include "ublox.h"
57 #include "vcp.h"
58 
59 #include <revo_f4.h>
60 
61 #include <cstdbool>
62 #include <cstddef>
63 #include <cstdint>
64 
65 namespace rosflight_firmware
66 {
67 class AirbourneBoard : public Board
68 {
69 private:
73  Serial *current_serial_; // A pointer to the serial stream currently in use.
93 
94  enum SerialDevice : uint32_t
95  {
98  };
100 
101  RC_BASE *rc_ = nullptr;
102 
103  std::function<void()> imu_callback_;
104 
106 
107  float _accel_scale = 1.0;
108  float _gyro_scale = 1.0;
109 
110  enum
111  {
115  };
117 
119  uint64_t imu_time_us_;
120 
121 public:
122  AirbourneBoard();
123 
124  // setup
125  void init_board() override;
126  void board_reset(bool bootloader) override;
127 
128  // clock
129  uint32_t clock_millis() override;
130  uint64_t clock_micros() override;
131  void clock_delay(uint32_t milliseconds) override;
132 
133  // serial
134  void serial_init(uint32_t baud_rate, uint32_t dev) override;
135  void serial_write(const uint8_t *src, size_t len) override;
136  uint16_t serial_bytes_available() override;
137  uint8_t serial_read() override;
138  void serial_flush() override;
139 
140  // sensors
141  void sensors_init() override;
142  uint16_t num_sensor_errors() override;
143 
144  bool new_imu_data() override;
145  bool imu_read(float accel[3], float *temperature, float gyro[3], uint64_t *time_us) override;
146  void imu_not_responding_error() override;
147 
148  bool mag_present() override;
149  void mag_update() override;
150  void mag_read(float mag[3]) override;
151 
152  bool baro_present() override;
153  void baro_update() override;
154  void baro_read(float *pressure, float *temperature) override;
155 
156  bool diff_pressure_present() override;
157  void diff_pressure_update() override;
158  void diff_pressure_read(float *diff_pressure, float *temperature) override;
159 
160  bool sonar_present() override;
161  void sonar_update() override;
162  float sonar_read() override;
163 
164  bool gnss_present() override;
165  void gnss_update() override;
166 
167  bool battery_voltage_present() const override;
168  float battery_voltage_read() const override;
169  void battery_voltage_set_multiplier(double multiplier) override;
170 
171  bool battery_current_present() const override;
172  float battery_current_read() const override;
173  void battery_current_set_multiplier(double multiplier) override;
174 
175  // GNSS
176  GNSSData gnss_read() override;
177  bool gnss_has_new_data() override;
178  GNSSFull gnss_full_read() override;
179  // RC
180  void rc_init(rc_type_t rc_type) override;
181  bool rc_lost() override;
182  float rc_read(uint8_t channel) override;
183 
184  // PWM
185  void pwm_init(uint32_t refresh_rate, uint16_t idle_pwm) override;
186  void pwm_disable() override;
187  void pwm_write(uint8_t channel, float value) override;
188 
189  // non-volatile memory
190  void memory_init() override;
191  bool memory_read(void *dest, size_t len) override;
192  bool memory_write(const void *src, size_t len) override;
193 
194  // LEDs
195  void led0_on() override;
196  void led0_off() override;
197  void led0_toggle() override;
198 
199  void led1_on() override;
200  void led1_off() override;
201  void led1_toggle() override;
202 
203  // Backup Data
204  void backup_memory_init() override;
205  bool backup_memory_read(void *dest, size_t len) override;
206  void backup_memory_write(const void *src, size_t len) override;
207  void backup_memory_clear(size_t len) override;
208 };
209 
210 } // namespace rosflight_firmware
211 
212 #endif // ROSFLIGHT_FIRMWARE_AIRBOURNE_BOARD_H
static volatile int16_t gyro[3]
Definition: drv_mpu6050.c:277
void backup_memory_write(const void *src, size_t len) override
void baro_read(float *pressure, float *temperature) override
float pressure
Definition: ms4525.c:41
float temperature
Definition: ms4525.c:41
Definition: spi.h:37
bool memory_write(const void *src, size_t len) override
A driver for the analog-digital converters available on the microcontroller.
AnalogDigitalConverter battery_adc_
Definition: ublox.h:14
void diff_pressure_read(float *diff_pressure, float *temperature) override
bool imu_read(float accel[3], float *temperature, float gyro[3], uint64_t *time_us) override
Definition: ms5611.h:38
Definition: rc_ppm.h:37
void clock_delay(uint32_t milliseconds) override
Definition: led.h:38
Definition: pwm.h:37
#define PWM_NUM_OUTPUTS
Definition: revo_f4.h:133
void backup_memory_clear(size_t len) override
void battery_voltage_set_multiplier(double multiplier) override
PWM_OUT esc_out_[PWM_NUM_OUTPUTS]
static volatile int16_t accel[3]
Definition: drv_mpu6050.c:276
bool battery_voltage_present() const override
float battery_voltage_read() const override
Definition: M25P16.h:36
std::function< void()> imu_callback_
void serial_init(uint32_t baud_rate, uint32_t dev) override
bool backup_memory_read(void *dest, size_t len) override
Definition: uart.h:42
float rc_read(uint8_t channel) override
Definition: vcp.h:19
float battery_current_read() const override
Definition: serial.h:44
bool memory_read(void *dest, size_t len) override
Definition: gpio.h:37
Definition: i2c.h:39
Definition: ms4525.h:35
void mag_read(float mag[3]) override
bool battery_current_present() const override
A driver for analog battery monitors.
void pwm_write(uint8_t channel, float value) override
void pwm_init(uint32_t refresh_rate, uint16_t idle_pwm) override
void serial_write(const uint8_t *src, size_t len) override
void board_reset(bool bootloader) override
void rc_init(rc_type_t rc_type) override
void battery_current_set_multiplier(double multiplier) override
uint16_t serial_bytes_available() override


rosflight_firmware
Author(s): Daniel Koch , James Jackson
autogenerated on Fri Oct 9 2020 03:17:15