From 61c8292cc4c6e16c9288b92b49ce61587a0c9343 Mon Sep 17 00:00:00 2001 From: Brendan Bartels <bbartels@iastate.edu> Date: Sat, 4 Mar 2017 08:33:07 -0600 Subject: [PATCH] wip: wire-up hardware in main and other fixes --- .../modular_quad_pid/src/application/main.c | 2 + .../modular_quad_pid/src/application/util.c | 11 ++++ .../modular_quad_pid/src/application/util.h | 2 + .../src/hardware/hw_impl_zybo.c | 62 +++++++++++++++++++ .../src/hardware/hw_impl_zybo.h | 14 ++++- 5 files changed, 88 insertions(+), 3 deletions(-) create mode 100644 quad/sw/modular_quad_pid/src/hardware/hw_impl_zybo.c diff --git a/quad/sw/modular_quad_pid/src/application/main.c b/quad/sw/modular_quad_pid/src/application/main.c index f06bab8c9..51c7e465f 100644 --- a/quad/sw/modular_quad_pid/src/application/main.c +++ b/quad/sw/modular_quad_pid/src/application/main.c @@ -25,6 +25,8 @@ int main() // Structures to be used throughout modular_structs_t structs = { }; + // Wire up hardware + setup_hardware(&structs.hardware_struct); // Initialize all required components and structs: // Uart, PWM receiver/generator, I2C, Sensor Board diff --git a/quad/sw/modular_quad_pid/src/application/util.c b/quad/sw/modular_quad_pid/src/application/util.c index 9262e49f4..864e61ce3 100644 --- a/quad/sw/modular_quad_pid/src/application/util.c +++ b/quad/sw/modular_quad_pid/src/application/util.c @@ -1,4 +1,5 @@ #include "util.h" +#include "../hardware/hw_impl_zybo.h" #include <stdlib.h> #include <stdio.h> @@ -13,6 +14,16 @@ extern int motor0_bias, motor1_bias, motor2_bias, motor3_bias; +void setup_hardware(hardware_t *hardware) { + hardware->i2c = create_zybo_i2c(); + hardware->pwm_inputs = create_zybo_pwm_inputs(); + hardware->pwm_outputs = create_zybo_pwm_outputs(); + hardware->uart = create_zybo_uart(); + hardware->global_timer = create_zybo_global_timer(); + hardware->axi_timer = create_zybo_axi_timer(); + hardware->mio7_led = create_zybo_mio7_led(); +} + /** * Reads all 6 receiver channels at once */ diff --git a/quad/sw/modular_quad_pid/src/application/util.h b/quad/sw/modular_quad_pid/src/application/util.h index 540c15f9a..5524b56ff 100644 --- a/quad/sw/modular_quad_pid/src/application/util.h +++ b/quad/sw/modular_quad_pid/src/application/util.h @@ -12,6 +12,8 @@ #include "controllers.h" #include "hw_iface.h" +void setup_hardware(hardware_t *hardware); + void read_rec_all(struct PWMInputDriver *pwm_input, u32 *mixer); int read_kill(int gear); int read_flap(int flap); diff --git a/quad/sw/modular_quad_pid/src/hardware/hw_impl_zybo.c b/quad/sw/modular_quad_pid/src/hardware/hw_impl_zybo.c new file mode 100644 index 000000000..9e74c42c3 --- /dev/null +++ b/quad/sw/modular_quad_pid/src/hardware/hw_impl_zybo.c @@ -0,0 +1,62 @@ +#include "hw_impl_zybo.h" + +struct UARTDriver create_zybo_uart() { + struct UARTDriver uart; + uart.state = NULL; + uart.reset = zybo_uart_reset; + uart.write = zybo_uart_write; + uart.read = zybo_uart_read; + return uart; +} + +struct PWMOutputDriver create_zybo_pwm_outputs() { + struct PWMOutputDriver pwm_outputs; + pwm_outputs.state = NULL; + pwm_outputs.reset = zybo_pwm_output_reset; + pwm_outputs.write = zybo_pwm_output_write; + return pwm_outputs; +} + +struct PWMInputDriver create_zybo_pwm_inputs() { + struct PWMInputDriver pwm_inputs; + pwm_inputs.state = NULL; + pwm_inputs.reset = zybo_pwm_input_reset; + pwm_inputs.read = zybo_pwm_input_read; + return pwm_inputs; +} + +struct I2CDriver create_zybo_i2c() { + struct I2CDriver i2c; + i2c.state = NULL; + i2c.reset = zybo_i2c_reset; + i2c.write = zybo_i2c_write; + i2c.read = zybo_i2c_read; + return i2c; +} + +struct TimerDriver create_zybo_global_timer() { + struct TimerDriver global_timer; + global_timer.state = NULL; + global_timer.reset = zybo_global_timer_reset; + global_timer.restart = zybo_global_timer_restart; + global_timer.read = zybo_global_timer_read; + return global_timer; +} + +struct TimerDriver create_zybo_axi_timer() { + struct TimerDriver axi_timer; + axi_timer.state = NULL; + axi_timer.reset = zybo_axi_timer_reset; + axi_timer.restart = zybo_axi_timer_restart; + axi_timer.read = zybo_axi_timer_read; + return axi_timer; +} + +struct LEDDriver create_zybo_mio7_led() { + struct LEDDriver mio7_led; + mio7_led.state = NULL; + mio7_led.reset = zybo_mio7_led_reset; + mio7_led.turn_on = zybo_mio7_led_turn_on; + mio7_led.turn_off = zybo_mio7_led_turn_off; + return mio7_led; +} diff --git a/quad/sw/modular_quad_pid/src/hardware/hw_impl_zybo.h b/quad/sw/modular_quad_pid/src/hardware/hw_impl_zybo.h index 4128f9339..04b408c04 100644 --- a/quad/sw/modular_quad_pid/src/hardware/hw_impl_zybo.h +++ b/quad/sw/modular_quad_pid/src/hardware/hw_impl_zybo.h @@ -44,8 +44,16 @@ int zybo_axi_timer_reset(struct TimerDriver *self); int zybo_axi_timer_restart(struct TimerDriver *self); int zybo_axi_timer_read(struct TimerDriver *self, unsigned long *us); -int zybo_led_reset(struct LEDDriver *self); -int zybo_led_turn_on(struct LEDDriver *self); -int zybo_led_turn_off(struct LEDDriver *self); +int zybo_mio7_led_reset(struct LEDDriver *self); +int zybo_mio7_led_turn_on(struct LEDDriver *self); +int zybo_mio7_led_turn_off(struct LEDDriver *self); + +struct UARTDriver create_zybo_uart(); +struct PWMOutputDriver create_zybo_pwm_outputs(); +struct PWMInputDriver create_zybo_pwm_inputs(); +struct I2CDriver create_zybo_i2c(); +struct TimerDriver create_zybo_global_timer(); +struct TimerDriver create_zybo_axi_timer(); +struct LEDDriver create_zybo_mio7_led(); #endif -- GitLab