54 PORTSetPinsDigitalIn(IOPORT_A, BIT_2);
60 uint32_t
const config1 =
70 ADC_AUTO_SAMPLING_ON |
74 uint32_t
const config2 =
79 ADC_OFFSET_CAL_DISABLE |
84 ADC_SAMPLES_PER_INT_2 |
88 uint32_t
const config3 =
98 uint32_t
const configport =
99 ENABLE_AN0_ANA | ENABLE_AN1_ANA;
102 uint32_t
const configdontscan =
103 SKIP_SCAN_AN2 | SKIP_SCAN_AN3 | SKIP_SCAN_AN4 | SKIP_SCAN_AN5 |
104 SKIP_SCAN_AN6 | SKIP_SCAN_AN7 | SKIP_SCAN_AN8 | SKIP_SCAN_AN9 |
105 SKIP_SCAN_AN10 | SKIP_SCAN_AN11 | SKIP_SCAN_AN12 | SKIP_SCAN_AN13 |
106 SKIP_SCAN_AN14 | SKIP_SCAN_AN15;
108 OpenADC10(config1, config2, config3, configport, configdontscan);
116 int16_t
const x = (int16_t) ReadADC10(0);
117 int16_t
const y = (int16_t) ReadADC10(1);
126 static int16_t
const pos_scale_factor =
128 static int16_t
const neg_scale_factor =
133 if (x_centered > 0) {
134 current.
x = x_centered * pos_scale_factor;
136 current.
x = x_centered * neg_scale_factor;
139 if (y_centered > 0) {
140 current.
y = y_centered * pos_scale_factor;
142 current.
y = y_centered * neg_scale_factor;
149 return PORTReadBits(IOPORT_A, BIT_2) != 0x0;
#define JOYSTICK_RAW_NEG_RANGE
#define JOYSTICK_RAW_MIDDLE
#define JOYSTICK_OUTPUT_RANGE
bool joystick_pushed(void)
Whether the joystick button is pressed.
#define JOYSTICK_RAW_POS_RANGE
struct joystick_vect joystick_get_pos(void)
Get most recent recorded joystick direction.
vector representing the joystick state.
void joystick_init(void)
Initialize joystick state and peripherals.