diff options
| author | spicyjpeg <88942473+spicyjpeg@users.noreply.github.com> | 2022-01-17 17:55:09 +0100 |
|---|---|---|
| committer | spicyjpeg <88942473+spicyjpeg@users.noreply.github.com> | 2022-01-17 17:55:09 +0100 |
| commit | e9475e283a82665fe6c19bebc3318b5084f15a2e (patch) | |
| tree | 5740f396d10a9580c3a39ca536544436898ff1b6 /examples/io | |
| parent | de38196a978548b61c4b45115d24ef743b9eef90 (diff) | |
| parent | 08de895e8582dbc70b639ae5f511ab9ebfb4d68a (diff) | |
| download | psn00bsdk-e9475e283a82665fe6c19bebc3318b5084f15a2e.tar.gz | |
Merge branch 'master' of github.com:Lameguy64/PSn00bSDK into latest-commit
Diffstat (limited to 'examples/io')
| -rw-r--r-- | examples/io/pads/main.c | 2 | ||||
| -rw-r--r-- | examples/io/pads/spi.c | 50 | ||||
| -rw-r--r-- | examples/io/pads/spi.h | 25 | ||||
| -rw-r--r-- | examples/io/system573/main.c | 30 |
4 files changed, 54 insertions, 53 deletions
diff --git a/examples/io/pads/main.c b/examples/io/pads/main.c index cc4ef56..d100482 100644 --- a/examples/io/pads/main.c +++ b/examples/io/pads/main.c @@ -127,7 +127,7 @@ void send_pad_cmd( uint8_t arg2, SPI_Callback callback ) { - SPI_request *req = SPI_CreateRequest(); + SPI_Request *req = SPI_CreateRequest(); req->len = 9; req->port = port; diff --git a/examples/io/pads/spi.c b/examples/io/pads/spi.c index e01b3f6..ef75ffc 100644 --- a/examples/io/pads/spi.c +++ b/examples/io/pads/spi.c @@ -54,21 +54,21 @@ /* Internal structures and globals */ -typedef struct _SPICONTEXT { - uint8_t tx_buff[SPI_BUFF_LEN]; - uint8_t rx_buff[SPI_BUFF_LEN]; - uint32_t tx_len, rx_len, port; - SPICALLBACK callback; -} SPICONTEXT; +typedef struct _SPI_CONTEXT { + uint8_t tx_buff[SPI_BUFF_LEN]; + uint8_t rx_buff[SPI_BUFF_LEN]; + uint32_t tx_len, rx_len, port; + SPI_Callback callback; +} SPI_Context; -static volatile SPICONTEXT ctx; -static volatile SPIREQUEST volatile *current_req; -static SPICALLBACK default_cb; +static volatile SPI_Context ctx; +static volatile SPI_Request volatile *current_req; +static SPI_Callback default_cb; /* Request queue management */ -static void prepare_poll_req(void) { - PADREQUEST *req = (PADREQUEST *) ctx.tx_buff; +static void _spi_create_poll_req(void) { + PadRequest *req = (PadRequest *) ctx.tx_buff; req->addr = 0x01; req->cmd = PAD_CMD_READ; @@ -82,7 +82,7 @@ static void prepare_poll_req(void) { ctx.callback = default_cb; } -static void prepare_next_req(void) { +static void _spi_next_req(void) { // Copy the contents of the first request in the queue into the TX buffer. memcpy((void *) ctx.tx_buff, (void *) current_req->data, current_req->len); @@ -93,7 +93,7 @@ static void prepare_next_req(void) { // Pop the first request from the queue by deallocating it and adjusting // the pointer to the first queue item. - SPIREQUEST *next = current_req->next; + SPI_Request *next = current_req->next; free((void *) current_req); current_req = next; @@ -101,7 +101,7 @@ static void prepare_next_req(void) { /* Interrupt handlers */ -static void poll_timer_tick(void) { +static void _spi_poll_irq_handler(void) { // Fetch the last response byte, which wasn't followed by a pulse on /ACK, // from the RX FIFO. if (JOY_STAT & 0x0002) @@ -112,9 +112,9 @@ static void poll_timer_tick(void) { // If the request queue is empty, create a pad polling request. if (current_req) - prepare_next_req(); + _spi_next_req(); else - prepare_poll_req(); + _spi_create_poll_req(); // Prepare the SPI port by clearing any pending IRQ, pulling /CS high and // enabling the /ACK IRQ. In order to communicate with controllers, /CS has @@ -132,7 +132,7 @@ static void poll_timer_tick(void) { JOY_TXRX = ctx.tx_buff[0]; } -static void spi_ack_handler(void) { +static void _spi_ack_irq_handler(void) { // Wait until /ACK is pulled up by the controller before sending the next // byte. According to nocash docs, this has to be done before resetting the // IRQ. @@ -166,8 +166,8 @@ static void spi_ack_handler(void) { /* Public API */ -SPIREQUEST *spi_new_request(void) { - SPIREQUEST *req = malloc(sizeof(SPIREQUEST)); +SPI_Request *SPI_CreateRequest(void) { + SPI_Request *req = malloc(sizeof(SPI_Request)); req->len = 0; req->port = 0; @@ -179,7 +179,7 @@ SPIREQUEST *spi_new_request(void) { if (!current_req) { current_req = req; } else { - volatile SPIREQUEST *volatile last = current_req; + volatile SPI_Request *volatile last = current_req; while (last->next) last = last->next; @@ -189,7 +189,7 @@ SPIREQUEST *spi_new_request(void) { return req; } -void spi_set_poll_rate(uint32_t value) { +void SPI_SetPollRate(uint32_t value) { TIM_CTRL(2) = 0x0258; // CLK/8 input, IRQ on reload, disable one-shot IRQ if (value < 65) @@ -198,21 +198,21 @@ void spi_set_poll_rate(uint32_t value) { TIM_RELOAD(2) = (F_CPU / 8) / value; } -void spi_init(SPICALLBACK callback) { +void SPI_Init(SPI_Callback callback) { // Disable the BIOS timer handler (which for some stupid reason is enabled // by default, even though it does nothing) and set up custom interrupt // handlers. EnterCriticalSection(); ChangeClearRCnt(2, 0); - InterruptCallback(6, &poll_timer_tick); - InterruptCallback(7, &spi_ack_handler); + InterruptCallback(6, &_spi_poll_irq_handler); + InterruptCallback(7, &_spi_ack_irq_handler); ExitCriticalSection(); JOY_CTRL = 0x0040; // Reset all registers JOY_MODE = 0x000d; // 1x multiplier, 8 data bits, no parity JOY_BAUD = 0x0088; // 250000 bps - spi_set_poll_rate(250); + SPI_SetPollRate(250); current_req = 0; default_cb = callback; } diff --git a/examples/io/pads/spi.h b/examples/io/pads/spi.h index 1c473cd..c50e065 100644 --- a/examples/io/pads/spi.h +++ b/examples/io/pads/spi.h @@ -9,23 +9,24 @@ #include <stdint.h> #include <psxpad.h> +// Maximum request/response length (34 bytes for pads, 140 for memory cards) //#define SPI_BUFF_LEN 34 #define SPI_BUFF_LEN 140 /* Request structures */ -typedef void (*SPICALLBACK)(uint32_t port, const volatile uint8_t *buff, size_t rx_len); +typedef void (*SPI_Callback)(uint32_t port, const volatile uint8_t *buff, size_t rx_len); -typedef struct _SPIREQUEST { +typedef struct _SPI_Request { union { - uint8_t data[SPI_BUFF_LEN]; - PADREQUEST pad_req; - MCDREQUEST mcd_req; + uint8_t data[SPI_BUFF_LEN]; + PadRequest pad_req; + MemCardRequest mcd_req; }; - uint32_t len, port; - SPICALLBACK callback; - struct _SPIREQUEST *next; -} SPIREQUEST; + uint32_t len, port; + SPI_Callback callback; + struct _SPI_Request *next; +} SPI_Request; /* Public API */ @@ -34,7 +35,7 @@ typedef struct _SPIREQUEST { * object must be populated afterwards by setting the length, callback and * filling in the TX data buffer. */ -SPIREQUEST *spi_new_request(void); +SPI_Request *SPI_CreateRequest(void); /** * @brief Changes the controller polling rate. The lowest supported rate is 65 @@ -43,7 +44,7 @@ SPIREQUEST *spi_new_request(void); * * @param value */ -void spi_set_poll_rate(uint32_t value); +void SPI_SetPollRate(uint32_t value); /** * @brief Installs the SPI and timer 2 interrupt handlers and starts the poll @@ -56,6 +57,6 @@ void spi_set_poll_rate(uint32_t value); * * @param callback */ -void spi_init(SPICALLBACK callback); +void SPI_Init(SPI_Callback callback); #endif diff --git a/examples/io/system573/main.c b/examples/io/system573/main.c index 95c3155..a06c4e5 100644 --- a/examples/io/system573/main.c +++ b/examples/io/system573/main.c @@ -185,9 +185,9 @@ typedef struct { uint8_t p1_joy, p1_btn; uint8_t p2_joy, p2_btn; uint8_t coin, dip_sw; -} JAMMA_INPUTS; +} JAMMAInputs; -void get_jamma_inputs(JAMMA_INPUTS *output) { +void get_jamma_inputs(JAMMAInputs *output) { uint16_t in1l = K573_IN1_L; uint16_t in1h = K573_IN1_H; uint16_t in2 = K573_IN2; @@ -225,14 +225,14 @@ void get_jamma_inputs(JAMMA_INPUTS *output) { void set_lights_analog(uint32_t lights) { uint32_t bits; - bits = (lights & 0x01010101) << 7; // Lamp 0 -> bit 7 - bits |= (lights & 0x02020202) << 5; // Lamp 1 -> bit 6 - bits |= (lights & 0x04040404) >> 1; // Lamp 2 -> bit 1 - bits |= (lights & 0x08080808) >> 3; // Lamp 3 -> bit 0 - bits |= (lights & 0x10101010) << 1; // Lamp 4 -> bit 5 - bits |= (lights & 0x20202020) >> 1; // Lamp 5 -> bit 4 - bits |= (lights & 0x40404040) >> 3; // Lamp 6 -> bit 3 - bits |= (lights & 0x80808080) >> 5; // Lamp 7 -> bit 2 + bits = (lights & 0x01010101) << 7; // Lamp n*8+0 -> bit n*8+7 + bits |= (lights & 0x02020202) << 5; // Lamp n*8+1 -> bit n*8+6 + bits |= (lights & 0x04040404) >> 1; // Lamp n*8+2 -> bit n*8+1 + bits |= (lights & 0x08080808) >> 3; // Lamp n*8+3 -> bit n*8+0 + bits |= (lights & 0x10101010) << 1; // Lamp n*8+4 -> bit n*8+5 + bits |= (lights & 0x20202020) >> 1; // Lamp n*8+5 -> bit n*8+4 + bits |= (lights & 0x40404040) >> 3; // Lamp n*8+6 -> bit n*8+3 + bits |= (lights & 0x80808080) >> 5; // Lamp n*8+7 -> bit n*8+2 K573_IO_BOARD[ANALOG_IO_LIGHTS0] = (bits) & 0xff; K573_IO_BOARD[ANALOG_IO_LIGHTS1] = (bits >> 8) & 0xff; @@ -247,10 +247,10 @@ void set_lights_analog(uint32_t lights) { void set_lights_digital(uint32_t lights) { uint32_t bits; - bits = (lights & 0x11111111); // Lamp 0 -> bit 0 - bits |= (lights & 0x22222222) << 1; // Lamp 1 -> bit 2 - bits |= (lights & 0x44444444) << 1; // Lamp 2 -> bit 3 - bits |= (lights & 0x88888888) >> 2; // Lamp 3 -> bit 1 + bits = (lights & 0x11111111); // Lamp n*4+0 -> bit n*4+0 + bits |= (lights & 0x22222222) << 1; // Lamp n*4+1 -> bit n*4+2 + bits |= (lights & 0x44444444) << 1; // Lamp n*4+2 -> bit n*4+3 + bits |= (lights & 0x88888888) >> 2; // Lamp n*4+3 -> bit n*4+1 K573_IO_BOARD[DIGITAL_IO_LIGHTS0] = ((bits) & 0xf) << 12; K573_IO_BOARD[DIGITAL_IO_LIGHTS1] = ((bits >> 4) & 0xf) << 12; @@ -298,7 +298,7 @@ int main(int argc, const char* argv[]) { while (1) { FntPrint(-1, "COUNTER=%d\n", counter++); - JAMMA_INPUTS inputs; + JAMMAInputs inputs; get_jamma_inputs(&inputs); FntPrint(-1, "\nJAMMA INPUTS:\n"); |
