void ConfigureOutputPorts(void) { bool err = true; // Configure the LED pins (LED0-LED3) as outputs err &= R_IO_PORT_Set ( PDL_IO_PORT_1_4|PDL_IO_PORT_1_5|PDL_IO_PORT_1_6|PDL_IO_PORT_1_7, PDL_IO_PORT_OUTPUT ); // Set LED pin outputs as high (all LEDs off) err &= R_IO_PORT_Write ( PDL_IO_PORT_1_4|PDL_IO_PORT_1_5|PDL_IO_PORT_1_6|PDL_IO_PORT_1_7, 1 ); // Configure the debug LCD data pins (DLCD7-DLCD4) as outputs err &= R_IO_PORT_Set ( PDL_IO_PORT_H_0|PDL_IO_PORT_H_1|PDL_IO_PORT_H_2| PDL_IO_PORT_H_3, PDL_IO_PORT_OUTPUT ); // Set debug LCD data pin (DLCD7-DLCD4) outputs as low err &= R_IO_PORT_Write ( PDL_IO_PORT_H_0|PDL_IO_PORT_H_1|PDL_IO_PORT_H_2| PDL_IO_PORT_H_3, 0 ); // Configure the debug LCD control pin (DLCDRS) and enable pin (DLCDE) as output err &= R_IO_PORT_Set ( PDL_IO_PORT_J_1|PDL_IO_PORT_J_3, PDL_IO_PORT_OUTPUT ); // Set the debug LCD control pin (DLCDRS) and enable pin (DLCDE) as output low err &= R_IO_PORT_Write ( PDL_IO_PORT_J_1|PDL_IO_PORT_J_3, 0 ); while(!err) ; }
/*””FUNC COMMENT””************************************************************* * Function Name: YRDKRX62N_RSPI_Select * Description : Enable device chip select on SPI channel * Arguments : uint16_t SPI chip_select defined in rdkrx62n.h * Return Value : none *””FUNC COMMENT END””*********************************************************/ void YRDKRX62N_RSPI_Select(uint16_t chip_select) { uint16_t rspi_cs; switch ( chip_select) { case SDMICRO_SELECTED: /* Enable the SD card */ rspi_cs = SDMICRO_CS; break; case FLASH_SELECTED: /* Enable Micron flash */ rspi_cs = FLASH_CS; break; case WIFI_SELECTED: /* Enable Redpine WiFi card */ rspi_cs = WIFI_CS; break; case LCD_SELECTED: /* Enable Okaya display */ rspi_cs = LCD_CS; break; default: return; } /* Assert slave select */ R_IO_PORT_Write(rspi_cs, 0); }
//------------------------------------------------------------------------------------------------- //------------------------------------------------------------------------------------------------- void GLCD_WriteCommand(unsigned char commandToWrite) { //GLCD_ReadStatus(); /* char i; rcv_data=commandToWrite; for(i=0;i<8;i++) { rcv_data=rcv_data<<1; TempLcd_data|=rcv_data&0x0100; TempLcd_data=TempLcd_data>>1; } commandToWrite=TempLcd_data; */ A0_1; SED1335_CS_0; RD_1; WR_0; R_IO_PORT_Write(PDL_IO_PORT_D,BitReverseTable[commandToWrite]); WR_1; }
void GLCD_WriteData(unsigned char dataToWrite) { /* char i; rcv_data=dataToWrite; for( i=0;i<8;i++) { rcv_data=rcv_data<<1; TempLcd_data|=rcv_data&0x0100; TempLcd_data=TempLcd_data>>1; } */ //dataToWrite=REVERSEBITS[dataToWrite];//TempLcd_data; //--GLCD_ReadStatus(); A0_0; SED1335_CS_0; RD_1; //SED1335_CONTROL_PORT &= ~(SED1335_WR); WR_0; R_IO_PORT_Write(PDL_IO_PORT_D,BitReverseTable[dataToWrite]);//SED1335_DATA_PORT = dataToWrite; WR_1; }
//------------------------------------------------------------------------------------------------- //------------------------------------------------------------------------------------------------- void GLCD_WriteCommand(unsigned char commandToWrite) { //GLCD_ReadStatus(); SED1335_CS_0; A0_1; RD_1; //SED1335_CONTROL_PORT &= ~(SED1335_WR); WR_0; R_IO_PORT_Write(PDL_IO_PORT_E,commandToWrite); //SED1335_CONTROL_PORT |= ( SED1335_WR); WR_1; }
//------------------------------------------------------------------------------------------------- void GLCD_WriteData(unsigned char dataToWrite) { //--GLCD_ReadStatus(); SED1335_CS_0; A0_0; RD_1; //SED1335_CONTROL_PORT &= ~(SED1335_WR); WR_0; R_IO_PORT_Write(PDL_IO_PORT_E,dataToWrite);//SED1335_DATA_PORT = dataToWrite; //SED1335_CONTROL_PORT |= (SED1335_WR); WR_1; }
/****************************************************************************** * Outline : ConfigureOutputPorts * Description : Configures the port and pin direction settings, and sets the * pin outputs to a safe level. * Argument : none * Return value : none ******************************************************************************/ void ConfigureOutputPorts(void) { /* Declare error flag */ bool err = true; /* Port 0 - all inputs (IRQ's from ethernet & WiFi) */ /* Port 1 - all inputs (IIC and USB settings will override these later */ /* Port 2 - USB signals */ err &= R_IO_PORT_Set ( USB0_EXICEN | USB_DPUPEA | USB_VBUSEN, PDL_IO_PORT_OUTPUT ); /* Port 3 - JTAG (P30, P31, P34), CAN (P32=Tx, P33=Rx), NMI (P35) */ err &= R_IO_PORT_Set ( CAN_WIFI_TX, PDL_IO_PORT_OUTPUT ); /* Port 4 - Switches (P40-P42), AIN (P43-P47) */ err &= R_IO_PORT_Set ( SW1 | SW2 | SW3 | JN1_AN3 | POTENTIOMETER | MICROPHONE | AUDIO_IN_R | PWMLP_IN, PDL_IO_PORT_INPUT | PDL_IO_PORT_INPUT_BUFFER_ON ); /* Port 5 - Audio (P55,P54), BCLK (P53), SCI (P52=Rx, P50=Tx), LCD-RS (P51) */ err &= R_IO_PORT_Set ( LCD_RS | LCD_A0 | BCLK | PWMLP_OUT | AMP_SHDN, PDL_IO_PORT_OUTPUT ); /* Port A outputs all LOW to start */ err &= R_IO_PORT_Write ( PDL_IO_PORT_A, 0 ); /* Port A - Expansion (PA0-PA2), Ether (PA3-PA5), Audio (PA6-PA7) */ err &= R_IO_PORT_Set ( JN2_SSLA1_B | JN2_SSLA2_B | JN2_SSLA3_B | ETH_MDIO | ETH_MDC | ETH_LINK | AUDIO_OUT_R | AUDIO_OUT_L , PDL_IO_PORT_OUTPUT ); /* Port B outputs all LOW to start */ err &= R_IO_PORT_Write ( PDL_IO_PORT_B, 0 ); /* Port B - Ether */ err &= R_IO_PORT_Set ( RMII_TX_EN | RMII_TXD0 | RMII_TXD1, PDL_IO_PORT_OUTPUT ); /* Port C - Chip selects, clock = high; IO reset = low */ err &= R_IO_PORT_Write ( PDL_IO_PORT_C, 0xF7 ); /* Port C - SPI (PC0-2, PC4-7), IO reset (PC3) */ err &= R_IO_PORT_Set ( FLASH_CS | WIFI_CS | LCD_CS | LCD_RESET | SDMICRO_CS | RSPI_SCLOCK | RSPI_MOSI, PDL_IO_PORT_OUTPUT ); /* Port D - All LED's off */ err &= R_IO_PORT_Write ( PDL_IO_PORT_D, 0xFF ); /* Port D - LED's */ err &= R_IO_PORT_Set ( LED14 | LED10 | LED6 | LED12 | LED8 | LED4 | LED15 | LED11, PDL_IO_PORT_OUTPUT ); /* Port E - All LED's off */ err &= R_IO_PORT_Write ( PDL_IO_PORT_E, 0x0F ); /* Port E - LED's */ err &= R_IO_PORT_Set ( LED7 | LED13 | LED9 | LED5, PDL_IO_PORT_OUTPUT ); /* Halt in while loop when RPDL errors detected */ while (!err); }
/******************************************************************************* * Outline : CB_CMT_Accelerometer * Description : CMT interrupt callback function. This callback function is * executed after every period of the CMT timer. The function * fetches the ADXL345 accelerometer readings & updates the LED's. * Argument : none * Return value : none *******************************************************************************/ void CB_CMT_Accelerometer(void) { #ifdef ACCELEROMETER_DEBUG /* Declare display buffer */ uint8_t lcd_buffer[13]; #endif uint16_t led; short adjusted_X, adjusted_Y, adjusted_Z; short slope = 0; /* Display the contents of lcd_buffer onto the debug LCD */ Accel_X = Accel_AxisRd(ADXL345_DATAX0_REG); Accel_Y = Accel_AxisRd(ADXL345_DATAY0_REG); Accel_Z = Accel_AxisRd(ADXL345_DATAZ0_REG); adjusted_X = Accel_X - Accel_X_Zero; adjusted_Y = Accel_Y - Accel_Y_Zero; adjusted_Z = Accel_Z - Accel_Z_Zero; /* calculate the slope, make sure not dividing by zero */ if ( adjusted_X == 0 ) adjusted_X = 1; slope = (100 * adjusted_Y) / adjusted_X; #ifdef ACCELEROMETER_DEBUG sprintf((char *)lcd_buffer, " x = %d" , adjusted_X); DisplayLCD(LCD_LINE4, lcd_buffer); sprintf((char *)lcd_buffer, " y = %d" , adjusted_Y); DisplayLCD(LCD_LINE5, lcd_buffer); sprintf((char *)lcd_buffer, " z = %d" , adjusted_Z); DisplayLCD(LCD_LINE6, lcd_buffer); #endif // turn all LEDs off /* Port D: All LED's off */ R_IO_PORT_Write( PDL_IO_PORT_D, 0xFF ); /* Port E: All LED's off */ R_IO_PORT_Write( PDL_IO_PORT_E, 0x0F ); /* ignore baseline noise */ if ((adjusted_X < 2) && (adjusted_X > -2 ) && (adjusted_Y < 2) && (adjusted_Y > -2 )) return; if ((slope > 0) && (slope < 55)) { if ( adjusted_X < 0 ) led = PDL_IO_PORT_D_2; // LED 6 else led = PDL_IO_PORT_D_3; // LED 12 } else if ((slope >= 55) && (slope < 170)) { if ( adjusted_X < 0 ) led = PDL_IO_PORT_E_3; // LED 5 else led = PDL_IO_PORT_D_7; // LED 11 } else if (slope >= 170) { if ( adjusted_X < 0 ) led = PDL_IO_PORT_D_5; // LED 4 else led = PDL_IO_PORT_D_1; // LED 10 } else if ((slope <= 0) && (slope > -55)) { if ( adjusted_X > 0 ) led = PDL_IO_PORT_E_1; // LED 13 else led = PDL_IO_PORT_E_0; // LED 7 } else if ((slope <= -55) && (slope > -170)) { if ( adjusted_X > 0 ) led = PDL_IO_PORT_D_0; // LED 14 else led = PDL_IO_PORT_D_4; // LED 8 } else if (slope <= -170) { if ( adjusted_X > 0 ) led = PDL_IO_PORT_D_6; // LED 15 else led = PDL_IO_PORT_E_2; // LED 9 } adjusted_Z = adjusted_Z ; /* Suppress compiler warning about not using this var */ // turn on the appropriate LED R_IO_PORT_Modify( led, PDL_IO_PORT_XOR, 1 ); }