Paparazzi UAS v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
Loading...
Searching...
No Matches
cc2500_compat.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2019 Tom van Dijk <tomvand@users.noreply.github.com>
3 *
4 * This code is based on the betaflight cc2500 and FrskyX implementation.
5 * https://github.com/betaflight/betaflight
6 *
7 * This file is part of paparazzi.
8 *
9 * paparazzi is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2, or (at your option)
12 * any later version.
13 *
14 * paparazzi is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with paparazzi; see the file COPYING. If not, write to
21 * the Free Software Foundation, 59 Temple Place - Suite 330,
22 * Boston, MA 02111-1307, USA.
23 */
24
25#include "cc2500_compat.h"
26
27#include "state.h"
28#include "mcu_periph/adc.h"
29#include "mcu_periph/gpio.h"
30#include "mcu_periph/sys_time.h"
32
33#include <stdbool.h>
34#include <assert.h>
35#include <math.h>
36
37
38// (unknown):
39struct attitude_t bf_attitude = { { 0, 0, 0 } }; // Dummy values
40
41
42// main/config/config.h:
43struct pidProfile_s *currentPidProfile; // Dummy values
44
45
46// main/config/feature.h:
51
52
53// main/common/filters.h:
54#define M_PI_FLOAT 3.14159265358979323846f
55float pt1FilterGain(float f_cut, float dT)
56{
57 float RC = 1 / ( 2 * M_PI_FLOAT * f_cut);
58 return dT / (RC + dT);
59}
60
61void pt1FilterInit(pt1Filter_t *filter, float k) {
62 filter->state = 0.0f;
63 filter->k = k;
64}
65
66void pt1FilterUpdateCutoff(pt1Filter_t *filter, float k) {
67 filter->k = k;
68}
69
70float pt1FilterApply(pt1Filter_t *filter, float input) {
71 filter->state = filter->state + filter->k * (input - filter->state);
72 return filter->state;
73}
74
75
76// main/drivers/time.h:
80
83}
84
86 return get_sys_time_usec();
87}
88
90 return get_sys_time_msec();
91}
92
93
94// main/drivers/adc.h:
96 (void) channel;
97 // Return current, as voltage is already reported by getLegacyBatteryVoltage
98 return (uint16_t)(electrical.current * 10000.0); // Assumed in 0.1mA
99}
100
101
102// main/drivers/rx_spi.h:
104 return TRUE;
105}
106
107
108// main/drivers/io.h:
110 return (IO_t)io;
111}
112
114 (void) io;
115 (void) owner;
116 (void) index;
117}
118
120 if (!io) return;
121 switch(cfg) {
122 case IOCFG_OUT_PP:
123 gpio_setup_output(io->port, io->pin);
124 break;
126 gpio_setup_input(io->port, io->pin);
127 break;
128 case IOCFG_IPU:
129 gpio_setup_input_pullup(io->port, io->pin);
130 break;
131 default:
132 assert("Invalid IO config" == NULL);
133 break;
134 }
135}
136
138 if (!gpio) return 0;
139 return gpio_get(gpio->port, gpio->pin);
140}
141
143 if (!io) return;
144 io->hi(io->port, io->pin);
145}
146
148 if (!io) return;
149 io->lo(io->port, io->pin);
150}
151
153 if (!io) return;
154 gpio_toggle(io->port, io->pin);
155}
156
157
158// main/fc/controlrate_profile.h:
160
161
162// main/flight/position.h:
164 return (int32_t)(stateGetPositionEnu_f()->z * 100.0);
165}
166
168 return (int16_t)(stateGetSpeedEnu_f()->z * 100.0);
169}
170
171
172// main/sensors/battery.h
174 return TRUE;
175}
176
178 return (uint16_t)((electrical.vsupply * 100.0 + 5) / 10.0); // ???
179}
180
182 return (uint16_t)(electrical.vsupply * 100.0); // 0.01V
183}
184
186 return 0;
187}
188
190 return TRUE;
191}
192
194 return (int32_t)(electrical.current * 100.0);
195}
196
198 return (int32_t)(electrical.charge * 1000.0);
199}
arch independent ADC (Analog to Digital Converter) API
void pt1FilterInit(pt1Filter_t *filter, float k)
bool bf_isAmperageConfigured(void)
bool bf_isBatteryVoltageConfigured(void)
void bf_delayMicroseconds(timeUs_t us)
int32_t bf_getEstimatedAltitudeCm(void)
#define M_PI_FLOAT
void bf_IOLo(IO_t io)
uint16_t bf_getBatteryVoltage(void)
bool bf_rxSpiDeviceInit(void)
struct pidProfile_s * currentPidProfile
timeUs_t bf_micros(void)
struct attitude_t bf_attitude
int32_t bf_getAmperage(void)
uint16_t bf_adcGetChannel(uint8_t channel)
int32_t bf_getMAhDrawn(void)
timeMs_t bf_millis(void)
uint8_t bf_getBatteryCellCount(void)
IO_t bf_IOGetByTag(ioTag_t io)
float pt1FilterGain(float f_cut, float dT)
bool bf_IORead(IO_t gpio)
int16_t bf_getEstimatedVario(void)
void bf_IOInit(IO_t io, uint8_t owner, uint8_t index)
void bf_delay(timeMs_t ms)
void bf_IOHi(IO_t io)
void pt1FilterUpdateCutoff(pt1Filter_t *filter, float k)
void bf_IOToggle(IO_t io)
uint16_t bf_getLegacyBatteryVoltage(void)
float pt1FilterApply(pt1Filter_t *filter, float input)
void bf_IOConfigGPIO(IO_t io, enum ioconfig_t cfg)
bool bf_featureIsEnabled(const uint32_t mask)
controlRateConfig_t * currentControlRateProfile
ioconfig_t
@ IOCFG_IN_FLOATING
@ IOCFG_IPU
@ IOCFG_OUT_PP
uint32_t timeMs_t
uint32_t timeUs_t
@ FEATURE_RX_SPI
@ FEATURE_TELEMETRY
void gpio_setup_input_pullup(ioportid_t port, uint16_t gpios)
Setup one or more pins of the given GPIO port as inputs with pull up resistor enabled.
Definition gpio_arch.c:47
void gpio_setup_output(ioportid_t port, uint16_t gpios)
Setup one or more pins of the given GPIO port as outputs.
Definition gpio_arch.c:33
void gpio_setup_input(ioportid_t port, uint16_t gpios)
Setup one or more pins of the given GPIO port as inputs.
Definition gpio_arch.c:40
static void gpio_toggle(ioportid_t port, uint16_t pin)
Toggle a gpio output to low level.
Definition gpio_arch.h:124
static uint8_t gpio_get(ioportid_t port, uint16_t pin)
Get level of a gpio.
Definition gpio_arch.h:94
void sys_time_usleep(uint32_t us)
sys_time_usleep(uint32_t us)
uint32_t get_sys_time_usec(void)
Get the time in microseconds since startup.
uint32_t get_sys_time_msec(void)
Get the time in milliseconds since startup.
struct Electrical electrical
Definition electrical.c:92
Interface for electrical status: supply voltage, current, battery status, etc.
float current
current in A
Definition electrical.h:47
float charge
consumed electric charge in Ah
Definition electrical.h:48
float vsupply
supply voltage in V
Definition electrical.h:45
Some architecture independent helper functions for GPIOs.
static struct EnuCoor_f * stateGetPositionEnu_f(void)
Get position in local ENU coordinates (float).
Definition state.h:848
static struct EnuCoor_f * stateGetSpeedEnu_f(void)
Get ground speed in local ENU coordinates (float).
Definition state.h:1058
uint16_t foo
Definition main_demo5.c:58
float z
in meters
API to get/set the generic vehicle states.
#define TRUE
Definition std.h:4
Architecture independent timing functions.
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
int int32_t
Typedef defining 32 bit int type.
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
short int16_t
Typedef defining 16 bit short type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.