Simon Ford
/
PlayStationController
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 #include "mbed.h" 00002 00003 SPI spi(p5, p6, p7); // mosi, miso, sclk (or "command", "data", "clock") 00004 DigitalOut cs(p25); // chip select (or "attention") 00005 00006 // setup the controller in to analog mode 00007 void ps2_analog_mode() { 00008 const char enter_config_mode[5] = {0x01, 0x43, 0x00, 0x01, 0x00}; 00009 const char enable_analog_mode[9] = {0x01, 0x44, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x00}; 00010 const char exit_config_mode[9] = {0x01, 0x43, 0x00, 0x00, 0x5A, 0x5A, 0x5A, 0x5A, 0x5A}; 00011 00012 cs = 0; 00013 for (int i=0; i<5; i++) { 00014 spi.write(enter_config_mode[i]); 00015 } 00016 cs = 1; 00017 00018 wait_us(1); 00019 00020 cs = 0; 00021 for (int i=0; i<9; i++) { 00022 spi.write(enable_analog_mode[i]); 00023 } 00024 cs = 1; 00025 00026 wait_us(1); 00027 00028 cs = 0; 00029 for (int i=0; i<9; i++) { 00030 spi.write(exit_config_mode[i]); 00031 } 00032 cs = 1; 00033 } 00034 00035 int main() { 00036 ps2_analog_mode(); 00037 00038 while (1) { 00039 const char poll_command[9] = {0x01, 0x42, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; 00040 char response[9]; 00041 00042 cs = 0; 00043 for (int i=0; i<9; i++) { 00044 response[i] = spi.write(poll_command[i]); 00045 } 00046 cs = 1; 00047 00048 printf("Digital %02X %02X Analog %02X %02X %02X %02X\n", response[3], response[4], response[5], response[6], response[7], response[8]); 00049 } 00050 } 00051
Generated on Thu Jul 14 2022 11:40:40 by 1.7.2