Go back to simple bit-banging in GamePadShift, fix problems

This commit is contained in:
Radomir Dopieralski 2019-04-11 10:16:55 +02:00
parent a7925930fa
commit b485e45f4f
2 changed files with 10 additions and 21 deletions

View File

@ -70,8 +70,8 @@ void gamepad_init_shift(digitalio_digitalinout_obj_t *data_pin,
common_hal_digitalio_digitalinout_switch_to_output(clock_pin, 0, DRIVE_MODE_PUSH_PULL);
gamepad_singleton->pins[1] = clock_pin;
common_hal_digitalio_digitalinout_switch_to_output(clock_pin, 1, DRIVE_MODE_PUSH_PULL);
common_hal_digitalio_digitalinout_switch_to_output(latch_pin, 1, DRIVE_MODE_PUSH_PULL);
gamepad_singleton->pins[2] = latch_pin;
gamepad_singleton->kind = GAMEPAD_KIND_PINS;
gamepad_singleton->kind = GAMEPAD_KIND_SHIFT;
}

View File

@ -54,32 +54,21 @@ void pressed_pins(gamepad_obj_t *self) {
void pressed_shift(gamepad_obj_t *self) {
static volatile uint8_t i = 8;
static volatile uint8_t clock = 0;
uint8_t bit = 1;
digitalio_digitalinout_obj_t* data_pin = self->pins[0];
digitalio_digitalinout_obj_t* clock_pin = self->pins[1];
digitalio_digitalinout_obj_t* latch_pin = self->pins[2];
if (clock == 0) {
common_hal_digitalio_digitalinout_set_value(clock_pin, 1);
clock = 1;
return;
}
if (i == 8) {
common_hal_digitalio_digitalinout_set_value(latch_pin, 0);
i = 9;
} else if (i == 9) {
common_hal_digitalio_digitalinout_set_value(latch_pin, 1);
i = 0;
} else {
if (common_hal_digitalio_digitalinout_get_value(data_pin)) {
self->pressed |= (1 << i);
}
i += 1;
}
for (int i = 0; i < 8; ++i) {
common_hal_digitalio_digitalinout_set_value(clock_pin, 0);
clock = 0;
if (common_hal_digitalio_digitalinout_get_value(data_pin)) {
self->pressed |= bit;
}
bit <<= 1;
common_hal_digitalio_digitalinout_set_value(clock_pin, 1);
}
common_hal_digitalio_digitalinout_set_value(latch_pin, 0);
}