Skip to content

Commit

Permalink
ODROID-GO support.
Browse files Browse the repository at this point in the history
  • Loading branch information
OtherCrashOverride committed Jul 13, 2018
1 parent cd7c068 commit a0dfe3c
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 35 deletions.
92 changes: 67 additions & 25 deletions components/prboom-esp32-compat/gamepad.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@
#include "driver/gpio.h"
#include <driver/adc.h>

#define ODROID_GAMEPAD_IO_X ADC1_CHANNEL_6
#define ODROID_GAMEPAD_IO_Y ADC1_CHANNEL_7
#define ODROID_GAMEPAD_IO_SELECT GPIO_NUM_27
#define ODROID_GAMEPAD_IO_START GPIO_NUM_39
#define ODROID_GAMEPAD_IO_A GPIO_NUM_32
#define ODROID_GAMEPAD_IO_B GPIO_NUM_33
#define ODROID_GAMEPAD_IO_MENU GPIO_NUM_13
#define ODROID_GAMEPAD_IO_VOLUME GPIO_NUM_0


typedef struct
{
Expand Down Expand Up @@ -86,24 +95,51 @@ int JoystickRead()
{
JoystickState state;

const int DEAD_ZONE = 1024;

int joyX = adc1_get_raw(ADC1_CHANNEL_6);
int joyY = adc1_get_raw(ADC1_CHANNEL_7);

state.Right = (joyX > (2048 + DEAD_ZONE));
state.Left = (joyX < (2048 - DEAD_ZONE));
state.Down = (joyY < (2048 - DEAD_ZONE));
state.Up = (joyY > (2048 + DEAD_ZONE));

state.Select = !(gpio_get_level(GPIO_NUM_13));
state.Start = !(gpio_get_level(GPIO_NUM_0));

//state.Select = !(gpio_get_level(GPIO_NUM_27));
//state.Start = !(gpio_get_level(GPIO_NUM_25));
int joyX = adc1_get_raw(ODROID_GAMEPAD_IO_X);
int joyY = adc1_get_raw(ODROID_GAMEPAD_IO_Y);

if (joyX > 2048 + 1024)
{
state.Left = 1;
state.Right = 0;
}
else if (joyX > 1024)
{
state.Left = 0;
state.Right = 1;
}
else
{
state.Left = 0;
state.Right = 0;
}

if (joyY > 2048 + 1024)
{
state.Up = 1;
state.Down = 0;
}
else if (joyY > 1024)
{
state.Up = 0;
state.Down = 1;
}
else
{
state.Up = 0;
state.Down = 0;
}

state.Select = !(gpio_get_level(ODROID_GAMEPAD_IO_SELECT));
state.Start = !(gpio_get_level(ODROID_GAMEPAD_IO_START));

state.A = !(gpio_get_level(ODROID_GAMEPAD_IO_A));
state.B = !(gpio_get_level(ODROID_GAMEPAD_IO_B));

//state.values[ODROID_INPUT_MENU] = !(gpio_get_level(ODROID_GAMEPAD_IO_MENU));
//state.values[ODROID_INPUT_VOLUME] = !(gpio_get_level(ODROID_GAMEPAD_IO_VOLUME));

state.A = !(gpio_get_level(GPIO_NUM_32));
state.B = !(gpio_get_level(GPIO_NUM_33));

int result = 0;

Expand Down Expand Up @@ -171,19 +207,25 @@ void gamepadInit(void)

void JoystickInit()
{
gpio_set_direction(GPIO_NUM_13, GPIO_MODE_INPUT); // Select (left - bottom)
gpio_set_direction(GPIO_NUM_0, GPIO_MODE_INPUT); // Start (right)
//GPIO_NUM_39 (left - top)
gpio_set_direction(ODROID_GAMEPAD_IO_SELECT, GPIO_MODE_INPUT);
gpio_set_pull_mode(ODROID_GAMEPAD_IO_SELECT, GPIO_PULLUP_ONLY);

//gpio_set_direction(GPIO_NUM_27, GPIO_MODE_INPUT); // Select
//gpio_set_direction(GPIO_NUM_25, GPIO_MODE_INPUT); // Start
gpio_set_direction(ODROID_GAMEPAD_IO_START, GPIO_MODE_INPUT);

gpio_set_direction(32, GPIO_MODE_INPUT); // A
gpio_set_direction(33, GPIO_MODE_INPUT); // B
gpio_set_direction(ODROID_GAMEPAD_IO_A, GPIO_MODE_INPUT);
gpio_set_pull_mode(ODROID_GAMEPAD_IO_A, GPIO_PULLUP_ONLY);

gpio_set_direction(ODROID_GAMEPAD_IO_B, GPIO_MODE_INPUT);
gpio_set_pull_mode(ODROID_GAMEPAD_IO_B, GPIO_PULLUP_ONLY);

adc1_config_width(ADC_WIDTH_12Bit);
adc1_config_channel_atten(ADC1_CHANNEL_6, ADC_ATTEN_11db); // JOY-X
adc1_config_channel_atten(ADC1_CHANNEL_7, ADC_ATTEN_11db); // JOY-Y
adc1_config_channel_atten(ODROID_GAMEPAD_IO_X, ADC_ATTEN_11db);
adc1_config_channel_atten(ODROID_GAMEPAD_IO_Y, ADC_ATTEN_11db);

gpio_set_direction(ODROID_GAMEPAD_IO_MENU, GPIO_MODE_INPUT);
gpio_set_pull_mode(ODROID_GAMEPAD_IO_MENU, GPIO_PULLUP_ONLY);

gpio_set_direction(ODROID_GAMEPAD_IO_VOLUME, GPIO_MODE_INPUT);
}

void jsInit() {
Expand Down
11 changes: 1 addition & 10 deletions components/prboom-esp32-compat/spi_lcd.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ static const ili_init_cmd_t ili_init_cmds[]={
#define TFT_RGB_BGR 0x08
#define TFT_CMD_SWRESET 0x01


// 2.4" LCD
DRAM_ATTR static const ili_init_cmd_t ili_init_cmds[] = {
// VCI=2.8V
Expand Down Expand Up @@ -122,16 +123,6 @@ DRAM_ATTR static const ili_init_cmd_t ili_init_cmds[] = {
{0xE0, {0x0F, 0x31, 0x2B, 0x0C, 0x0E, 0x08, 0x4E, 0xF1, 0x37, 0x07, 0x10, 0x03, 0x0E, 0x09, 0x00}, 15},
{0XE1, {0x00, 0x0E, 0x14, 0x03, 0x11, 0x07, 0x31, 0xC1, 0x48, 0x08, 0x0F, 0x0C, 0x31, 0x36, 0x0F}, 15},

// LUT
{0x2d, {0x01, 0x03, 0x05, 0x07, 0x09, 0x0b, 0x0d, 0x0f, 0x11, 0x13, 0x15, 0x17, 0x19, 0x1b, 0x1d, 0x1f,
0x21, 0x23, 0x25, 0x27, 0x29, 0x2b, 0x2d, 0x2f, 0x31, 0x33, 0x35, 0x37, 0x39, 0x3b, 0x3d, 0x3f,
0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x09, 0x0a, 0x0b, 0x0c, 0x0d,
0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c,
0x1d, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x26, 0x27, 0x28, 0x29, 0x2a,
0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39,
0x00, 0x00, 0x02, 0x04, 0x06, 0x08, 0x0a, 0x0c, 0x0e, 0x10, 0x12, 0x12, 0x14, 0x16, 0x18, 0x1a,
0x1c, 0x1e, 0x20, 0x22, 0x24, 0x26, 0x26, 0x28, 0x2a, 0x2c, 0x2e, 0x30, 0x32, 0x34, 0x36, 0x38}, 128},

{0x11, {0}, 0x80}, //Exit Sleep
{0x29, {0}, 0x80}, //Display on

Expand Down

0 comments on commit a0dfe3c

Please sign in to comment.