Skip to content
Snippets Groups Projects
Commit 61c8292c authored by bbartels's avatar bbartels Committed by dawehr
Browse files

wip: wire-up hardware in main

and other fixes
parent 17906096
No related branches found
No related tags found
1 merge request!9Abstract the hardware layer
......@@ -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
......
#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
*/
......
......@@ -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);
......
#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;
}
......@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment