-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
233 additions
and
455 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#pragma once | ||
|
||
#include "adc.h" | ||
#include "can.h" | ||
#include "gpio.h" | ||
#include "gpio_it.h" | ||
#include "gpio_mcu.h" | ||
#include "log.h" | ||
#include "status.h" | ||
#include "steering_setters.h" | ||
|
||
#define VOLTAGE_TOLERANCE_MV 20 | ||
// turn signal voltages | ||
#define TURN_LEFT_SIGNAL_VOLTAGE_MV 1200 | ||
#define TURN_RIGHT_SIGNAL_VOLTAGE_MV 2130 | ||
#define NEUTRAL_SIGNAL_VOLTAGE_MV 2610 | ||
// cruise control voltages | ||
#define CRUISE_CONTROl_STALK_SPEED_INCREASE_VOLTAGE_MV 1650 | ||
#define CRUISE_CONTROl_STALK_SPEED_DECREASE_VOLTAGE_MV 790 | ||
#define CRUISE_CONTROl_STALK_NEUTRAL_VOLTAGE_MV 3300 | ||
|
||
#define TURN_SIGNAL_GPIO \ | ||
{ .port = GPIO_PORT_A, .pin = 5 } | ||
|
||
#define CC_CHANGE_GPIO \ | ||
{ .port = GPIO_PORT_A, .pin = 6 } | ||
|
||
#define CC_TOGGLE_GPIO \ | ||
{ .port = GPIO_PORT_A, .pin = 7 } | ||
|
||
#define CC_TOGGLE_EVENT 0x0 | ||
|
||
// TurnSignal Values for each state | ||
typedef enum TurnSignalState { | ||
TURN_SIGNAL_OFF = 0, | ||
TURN_SIGNAL_LEFT, | ||
TURN_SIGNAL_RIGHT, | ||
} TurnSignalState; | ||
|
||
// CruiseControl Mask Values for each state | ||
typedef enum { | ||
CC_DECREASE_MASK = 0x01, | ||
CC_INCREASE_MASK = 0x02, | ||
CC_TOGGLE_MASK = 0x04, | ||
} CruiseControlMask; | ||
// Initializes the ADC input for the ctrl stalk as well as the gpio interrupt for the toggle | ||
// Must be called before adc_init() | ||
StatusCode steering_init(); | ||
// Reads the analog input, determines a light state, and sets the requisite value in the can message | ||
// Also reads the toggle notification state and sets the requisite value in the can message | ||
void steering_input(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#include "steering_task.h" | ||
|
||
#define CC_INPUT g_tx_struct.steering_info_input_cc | ||
|
||
static const GpioAddress turn_signal_address = TURN_SIGNAL_GPIO; | ||
static const GpioAddress cc_address = CC_CHANGE_GPIO; | ||
static const GpioAddress cc_toggle_address = CC_TOGGLE_GPIO; | ||
static Event STEERING_EVENT; | ||
|
||
StatusCode steering_init(Task *task) { | ||
// Initialize Pins | ||
gpio_init_pin(&turn_signal_address, GPIO_ANALOG, GPIO_STATE_LOW); | ||
gpio_init_pin(&cc_address, GPIO_ANALOG, GPIO_STATE_LOW); | ||
gpio_init_pin(&cc_toggle_address, GPIO_ANALOG, GPIO_STATE_LOW); | ||
// Set up ADC | ||
adc_add_channel(turn_signal_address); | ||
adc_add_channel(cc_address); | ||
// Initialize interrupt settings | ||
InterruptSettings it_settings = { | ||
.priority = INTERRUPT_PRIORITY_NORMAL, | ||
.type = INTERRUPT_TYPE_INTERRUPT, | ||
.edge = INTERRUPT_EDGE_FALLING, | ||
}; | ||
// Initialize interrupt | ||
gpio_it_register_interrupt(&cc_toggle_address, &it_settings, CC_TOGGLE_EVENT, task); | ||
return STATUS_CODE_OK; | ||
} | ||
|
||
void steering_input(uint32_t notification) { | ||
uint16_t control_stalk_data; | ||
set_steering_info_input_cc(0); | ||
// Read ADC of pin set by turn signal lights | ||
adc_read_converted(turn_signal_address, &control_stalk_data); | ||
// Determine if it's a left, right or off signal | ||
if (control_stalk_data > TURN_LEFT_SIGNAL_VOLTAGE_MV - VOLTAGE_TOLERANCE_MV && | ||
control_stalk_data < TURN_LEFT_SIGNAL_VOLTAGE_MV + VOLTAGE_TOLERANCE_MV) { | ||
set_steering_info_input_lights(TURN_SIGNAL_LEFT); | ||
} else if (control_stalk_data > TURN_RIGHT_SIGNAL_VOLTAGE_MV - VOLTAGE_TOLERANCE_MV && | ||
control_stalk_data < TURN_RIGHT_SIGNAL_VOLTAGE_MV + VOLTAGE_TOLERANCE_MV) { | ||
set_steering_info_input_lights(TURN_SIGNAL_RIGHT); | ||
} else { | ||
set_steering_info_input_lights(TURN_SIGNAL_OFF); | ||
} | ||
// Read ADC of pin set by cruise control | ||
// Determine if it read an increase or decrease signal | ||
adc_read_converted(cc_address, &control_stalk_data); | ||
if (control_stalk_data > CRUISE_CONTROl_STALK_SPEED_INCREASE_VOLTAGE_MV - VOLTAGE_TOLERANCE_MV && | ||
control_stalk_data < CRUISE_CONTROl_STALK_SPEED_INCREASE_VOLTAGE_MV + VOLTAGE_TOLERANCE_MV) { | ||
// toggle second bit to 1 | ||
set_steering_info_input_cc(CC_INCREASE_MASK | CC_INPUT); | ||
} else if (control_stalk_data > | ||
CRUISE_CONTROl_STALK_SPEED_DECREASE_VOLTAGE_MV - VOLTAGE_TOLERANCE_MV && | ||
control_stalk_data < | ||
CRUISE_CONTROl_STALK_SPEED_DECREASE_VOLTAGE_MV + VOLTAGE_TOLERANCE_MV) { | ||
// toggle first bit to 1 | ||
set_steering_info_input_cc(CC_DECREASE_MASK | CC_INPUT); | ||
} | ||
if (notify_get(¬ification) == STATUS_CODE_OK) { | ||
while (event_from_notification(¬ification, &STEERING_EVENT) == STATUS_CODE_INCOMPLETE) { | ||
if (STEERING_EVENT == CC_TOGGLE_EVENT) { | ||
set_steering_info_input_cc(CC_TOGGLE_MASK | CC_INPUT); | ||
} | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.