NinjaFlight
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
system_calls.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <stdint.h>
4 #include <stddef.h>
5 
6 typedef int32_t sys_millis_t;
7 typedef int32_t sys_micros_t;
8 
32 #define SYSTEM_GYRO_RANGE 2000
33 
36 #define SYSTEM_ACC_1G 1000
37 
40 #define SYSTEM_GYRO_SCALE ((float)SYSTEM_GYRO_RANGE / (int16_t)0x7fff)
41 
58  void (*write_motor)(const struct system_calls_pwm *self, uint8_t id, uint16_t value);
67  void (*write_servo)(const struct system_calls_pwm *self, uint8_t id, uint16_t value);
73  uint16_t (*read_pwm)(const struct system_calls_pwm *self, uint8_t chan);
79  uint16_t (*read_ppm)(const struct system_calls_pwm *self, uint8_t chan);
80 };
81 
94  int (*read_gyro)(const struct system_calls_imu *self, int16_t out[3]);
104  int (*read_acc)(const struct system_calls_imu *self, int16_t out[3]);
105  int (*read_pressure)(const struct system_calls_imu *self, uint16_t *out);
106  int (*read_temperature)(const struct system_calls_imu *self, uint16_t *out);
107 };
108 
116  void (*on)(const struct system_calls_leds *self, uint8_t led, bool on);
120  void (*toggle)(const struct system_calls_leds *self, uint8_t led);
121 };
122 
130  void (*on)(const struct system_calls_beeper *self, bool on);
131 };
132 
142  sys_micros_t (*micros)(const struct system_calls_time *self);
143 };
144 
149  uint16_t page_size;
150  uint16_t num_pages;
151 };
152 
166  int (*read)(const struct system_calls_eeprom *self, void *dst, uint16_t addr, size_t size);
171  int (*write)(const struct system_calls_eeprom *self, uint16_t addr, const void *src, size_t size);
175  int (*erase_page)(const struct system_calls_eeprom *self, uint16_t addr);
179  void (*get_info)(const struct system_calls_eeprom *self, struct system_eeprom_info *info);
180 };
181 
194  int (*read_range)(const struct system_calls_range *self, uint16_t deg, uint16_t *range);
195 };
196 
200 struct system_calls {
208 };
209 
210 #define sys_led_on(sys, id) sys->leds.on(&(sys)->leds, id, true)
211 #define sys_led_off(sys, id) sys->leds.on(&(sys)->leds, id, false)
212 #define sys_led_toggle(sys, id) sys->leds.toggle(&(sys)->leds, id)
213 
214 #define sys_beeper_on(sys) sys->beeper.on(&(sys)->beeper, true)
215 #define sys_beeper_off(sys) sys->beeper.on(&(sys)->beeper, false)
216 
217 #define sys_millis(sys) (sys->time.micros(&(sys)->time) / 1000)
218 #define sys_micros(sys) (sys->time.micros(&(sys)->time))
219 
220 #define sys_gyro_read(sys, data) (sys->imu.read_gyro(&(sys)->imu, data))
221 #define sys_acc_read(sys, data) (sys->imu.read_acc(&(sys)->imu, data))
222 #define sys_get_pressure(sys, data) (sys->imu.read_pressure(&(sys)->imu, data))
223 #define sys_get_temperature(sys, data) (sys->imu.read_temperature(&(sys)->imu, data))
224 
225 #define sys_motor_write(sys, id, val) (sys->pwm.write_motor(&(sys)->pwm, id, val))
226 #define sys_servo_write(sys, id, val) (sys->pwm.write_servo(&(sys)->pwm, id, val))
227 
228 #define sys_eeprom_write(sys, addr, src, size) (sys->eeprom.write(&(sys)->eeprom, addr, src, size))
229 #define sys_eeprom_read(sys, dst, addr, size) (sys->eeprom.read(&(sys)->eeprom, dst, addr, size))
230 #define sys_eeprom_get_info(sys, info) (sys->eeprom.get_info(&(sys)->eeprom, info))
231 #define sys_eeprom_erase_page(sys, addr) (sys->eeprom.erase_page(&(sys)->eeprom, addr))
232 
233 #define sys_range_read(sys, deg, dst) (sys->range.read_range(&(sys)->range, deg, dst))
234 
struct system_calls_pwm pwm
Definition: system_calls.h:201
Definition: system_calls.h:161
int(* write)(const struct system_calls_eeprom *self, uint16_t addr, const void *src, size_t size)
Definition: system_calls.h:171
Definition: system_calls.h:136
Definition: system_calls.h:148
struct system_calls_range range
Definition: system_calls.h:207
pwm related system calls
Definition: system_calls.h:47
void(* get_info)(const struct system_calls_eeprom *self, struct system_eeprom_info *info)
Definition: system_calls.h:179
Definition: imu.h:49
Definition: beeper.h:69
int(* read)(const struct system_calls_eeprom *self, void *dst, uint16_t addr, size_t size)
Definition: system_calls.h:166
void(* write_servo)(const struct system_calls_pwm *self, uint8_t id, uint16_t value)
Definition: system_calls.h:67
int(* read_pressure)(const struct system_calls_imu *self, uint16_t *out)
Definition: system_calls.h:105
void(* toggle)(const struct system_calls_leds *self, uint8_t led)
Definition: system_calls.h:120
int32_t sys_millis_t
Definition: system_calls.h:6
void(* on)(const struct system_calls_beeper *self, bool on)
Definition: system_calls.h:130
Definition: system_calls.h:85
int32_t sys_micros_t
Definition: system_calls.h:7
uint16_t num_pages
Definition: system_calls.h:150
Definition: system_calls.h:112
int(* read_gyro)(const struct system_calls_imu *self, int16_t out[3])
Definition: system_calls.h:94
int(* erase_page)(const struct system_calls_eeprom *self, uint16_t addr)
Definition: system_calls.h:175
channelRange_t range
Definition: rc_adjustments.h:31
Definition: system_calls.h:126
Definition: system_calls.h:200
void(* write_motor)(const struct system_calls_pwm *self, uint8_t id, uint16_t value)
Definition: system_calls.h:58
int(* read_range)(const struct system_calls_range *self, uint16_t deg, uint16_t *range)
Definition: system_calls.h:194
sys_micros_t(* micros)(const struct system_calls_time *self)
Definition: system_calls.h:142
struct system_calls_leds leds
Definition: system_calls.h:203
uint16_t addr
Definition: config.c:90
int(* read_temperature)(const struct system_calls_imu *self, uint16_t *out)
Definition: system_calls.h:106
struct system_calls_eeprom eeprom
Definition: system_calls.h:206
int(* read_acc)(const struct system_calls_imu *self, int16_t out[3])
Definition: system_calls.h:104
uint16_t page_size
Definition: system_calls.h:149
struct system_calls_time time
Definition: system_calls.h:205
uint16_t(* read_ppm)(const struct system_calls_pwm *self, uint8_t chan)
Definition: system_calls.h:79
void(* on)(const struct system_calls_leds *self, uint8_t led, bool on)
Definition: system_calls.h:116
uint16_t(* read_pwm)(const struct system_calls_pwm *self, uint8_t chan)
Definition: system_calls.h:73
Definition: system_calls.h:190