bool IO::getState() const { if(this->onIsHigh) return (GPIO_ReadValue(this->port) & (1<<this->pin)); else return !(GPIO_ReadValue(this->port) & (1<<this->pin)); }
uint8_t Joystick_GetStatus(void) { uint8_t ret = NO_BUTTON_PRESSED; if((GPIO_ReadValue(JOYSTICK_UP_GPIO_PORT_NUM) & (1<<JOYSTICK_UP_GPIO_BIT_NUM)) == 0x00) { ret |= JOY_UP; } else if((GPIO_ReadValue(JOYSTICK_DOWN_GPIO_PORT_NUM) & (1<<JOYSTICK_DOWN_GPIO_BIT_NUM)) == 0x00) { ret |= JOY_DOWN; } else if((GPIO_ReadValue(JOYSTICK_LEFT_GPIO_PORT_NUM) & (1<<JOYSTICK_LEFT_GPIO_BIT_NUM)) == 0x00) { ret |= JOY_LEFT; } else if((GPIO_ReadValue(JOYSTICK_RIGHT_GPIO_PORT_NUM) & (1<<JOYSTICK_RIGHT_GPIO_BIT_NUM)) == 0x00) { ret |= JOY_RIGHT; } else if((GPIO_ReadValue(JOYSTICK_PRESS_GPIO_PORT_NUM) & (1<<JOYSTICK_PRESS_GPIO_BIT_NUM)) == 0x00) { ret |= JOY_PRESS; } return ret; }
int main(void) { SystemInit(); CGU_Init(); // Configure GPIO pins connected to LEDs as outputs scu_pinmux(D3_SCU_PORT, D3_SCU_PIN, MD_BUK, FUNC4); GPIO_SetDir(D3_GPIO_PORT, D3_GPIO_MASK, 1); scu_pinmux(D4_SCU_PORT, D4_SCU_PIN, MD_BUK, FUNC4); GPIO_SetDir(D4_GPIO_PORT, D4_GPIO_MASK, 1); scu_pinmux(D5_SCU_PORT, D5_SCU_PIN, MD_BUK, FUNC4); GPIO_SetDir(D5_GPIO_PORT, D5_GPIO_MASK, 1); scu_pinmux(D6_SCU_PORT, D6_SCU_PIN, MD_BUK, FUNC4); GPIO_SetDir(D6_GPIO_PORT, D6_GPIO_MASK, 1); // Configure GPIO pins connected to push buttons as inputs scu_pinmux(S1_SCU_PORT, S1_SCU_PIN, MD_BUK | MD_EZI, FUNC4); GPIO_SetDir(S1_GPIO_PORT, S1_GPIO_MASK, 0); scu_pinmux(S2_SCU_PORT, S2_SCU_PIN, MD_BUK | MD_EZI, FUNC4); GPIO_SetDir(S2_GPIO_PORT, S2_GPIO_MASK, 0); scu_pinmux(S3_SCU_PORT, S3_SCU_PIN, MD_BUK | MD_EZI, FUNC4); GPIO_SetDir(S3_GPIO_PORT, S3_GPIO_MASK, 0); scu_pinmux(S4_SCU_PORT, S4_SCU_PIN, MD_BUK | MD_EZI, FUNC4); GPIO_SetDir(S4_GPIO_PORT, S4_GPIO_MASK, 0); while(1) { if (GPIO_ReadValue(S1_GPIO_PORT) & S1_GPIO_MASK) GPIO_ClearValue(D3_GPIO_PORT, D3_GPIO_MASK); else GPIO_SetValue(D3_GPIO_PORT, D3_GPIO_MASK); if (GPIO_ReadValue(S2_GPIO_PORT) & S2_GPIO_MASK) GPIO_ClearValue(D4_GPIO_PORT, D4_GPIO_MASK); else GPIO_SetValue(D4_GPIO_PORT, D4_GPIO_MASK); if (GPIO_ReadValue(S3_GPIO_PORT) & S3_GPIO_MASK) GPIO_ClearValue(D5_GPIO_PORT, D5_GPIO_MASK); else GPIO_SetValue(D5_GPIO_PORT, D5_GPIO_MASK); if (GPIO_ReadValue(S4_GPIO_PORT) & S4_GPIO_MASK) GPIO_ClearValue(D6_GPIO_PORT, D6_GPIO_MASK); else GPIO_SetValue(D6_GPIO_PORT, D6_GPIO_MASK); } }
// The platform I/O functions pio_type platform_pio_op( unsigned port, pio_type pinmask, int op ) { pio_type retval = 1; switch( op ) { case PLATFORM_IO_PORT_SET_VALUE: GPIO_SetValue(port, pinmask); break; case PLATFORM_IO_PIN_SET: GPIO_SetValue(port, pinmask); break; case PLATFORM_IO_PIN_CLEAR: GPIO_ClearValue(port, pinmask); break; case PLATFORM_IO_PORT_DIR_OUTPUT: GPIO_SetDir(port, 0xFFFFFFFF, 1); break; case PLATFORM_IO_PIN_DIR_OUTPUT: GPIO_SetDir(port, pinmask, 1); break; case PLATFORM_IO_PORT_DIR_INPUT: GPIO_SetDir(port, 0xFFFFFFFF, 0); break; case PLATFORM_IO_PIN_DIR_INPUT: GPIO_SetDir(port, pinmask, 0); break; case PLATFORM_IO_PORT_GET_VALUE: retval = GPIO_ReadValue(port); break; case PLATFORM_IO_PIN_GET: retval = ( GPIO_ReadValue(port) & pinmask ) ? 1 : 0; break; default: retval = 0; break; } return retval; }
void SysTick_Handler(void) { static uint32_t prsk = SCAN_PERIOD; uint8_t i, led; uint8_t *command = (uint8_t *)CMD_BASE_ADDR; if (--prsk == 0) { prsk = SCAN_PERIOD; led = 0; for (i = 0; i < 4; i++) { if ((GPIO_ReadValue(buttons[i].port) & buttons[i].mask) == 0) { led |= (1 << i); } } // Send command command[0] = CMD_SET_LED; command[1] = led; __DSB(); // ensure completion of memory access __SEV(); // send event } }
/****************************************************************************** * * Description: * Read the joystick status * * Returns: * The joystick status. The returned value is a bit mask. More than one * direction may be active at any given time (e.g. UP and RIGHT) * *****************************************************************************/ uint8_t joystick_read(void) { uint8_t status = 0; uint32_t pinVal = 0; pinVal = GPIO_ReadValue(GPIO_PORT); pinVal = pinVal; if ((pinVal & GPIO_PIN_DOWN) == 0) { status |= JOYSTICK_DOWN; } if ((pinVal & GPIO_PIN_RIGHT) == 0) { status |= JOYSTICK_RIGHT; } if ((pinVal & GPIO_PIN_UP) == 0) { status |= JOYSTICK_UP; } if ((pinVal & GPIO_PIN_LEFT) == 0) { status |= JOYSTICK_LEFT; } if ((pinVal & GPIO_PIN_CENTER) == 0) { status |= JOYSTICK_CENTER; } return status; }
FunctionalState GSM_GetStatus(void) { if(GPIO_ReadValue(GPIO2)&0x200) { return ENABLE; } else return DISABLE; }
uint32_t Buttons_GetStatus(void) { uint8_t ret = NO_BUTTON_PRESSED; if((GPIO_ReadValue(BUTTONS_BUTTON1_GPIO_PORT_NUM) & (1UL<<BUTTONS_BUTTON1_GPIO_BIT_NUM)) == 0x00) { ret |= BUTTONS_BUTTON1; } return ret; }
char ads7843_gpio_get_value(char pin) { switch(pin) { case TS_PENIRQ: { if((GPIO_ReadValue(4)&1)!=0) return 1; else return 0; } default: return 0; } }
void GetInReport (void) { uint32_t kbd_val; kbd_val = GPIO_ReadValue(KBD_PORT_NUM) & KBD_MASK; InReport = 0x00; if ((kbd_val & KBD_UP) == 0) InReport |= 0x01; /* up pressed means 0 */ if ((kbd_val & KBD_LEFT) == 0) InReport |= 0x02; /* left pressed means 0 */ if ((kbd_val & KBD_RIGHT) == 0) InReport |= 0x04; /* right pressed means 0 */ if ((kbd_val & KBD_SELECT) == 0) InReport |= 0x08; /* select pressed means 0 */ if ((kbd_val & KBD_DOWN) == 0) InReport |= 0x10; /* down pressed means 0 */ }
int _GPIO_ReadValue(uint8_t * args) { uint8_t * arg_ptr; uint8_t portNum; if ((arg_ptr = (uint8_t *) strtok(NULL, " ")) == NULL) return 1; portNum = (uint8_t) strtoul((char *) arg_ptr, NULL, 16); sprintf((char *) str, "%x\r\n", (unsigned int) GPIO_ReadValue(portNum)); writeUSBOutString(str); return 0; }
uint8_t GetLineValue(void) { uint32_t tmp; uint8_t i,rtn = 0; for(i = 4;i < 8;i++) { tmp = GPIO_ReadValue (KeyBoardConfig[i][0]); if(!(tmp&(1<<KeyBoardConfig[i][1]))) { rtn |= 1<<i; } } return rtn; }
/* Private: Detect if a USB host is actually attached, regardless of VBUS. * * This is a bit hacky, as normally you should rely on VBUS to detect if USB is * connected. See vbusDetected() for reasons why we need this workaround on the * current prototype. * * Returns true of there is measureable activity on the D- USB line. */ bool usbHostDetected() { static int debounce = 0; if((GPIO_ReadValue(USB_DM_PORT) & (1 << USB_DM_PIN)) == 0) { ++debounce; } else { debounce = 0; } if(debounce > USB_HOST_DETECT_DEBOUNCE_VALUE) { debounce = 0; return false; } return true; }
/****************************************************************************** * * Description: * Get buttons state * * Returns: * buttons state * *****************************************************************************/ uint8_t btn_get (void) { uint32_t v = GPIO_ReadValue(2); uint8_t res = 0; if ((v & (1<<11)) == 0) { res |= BTN_SW2; } if ((v & (1<<12)) == 0) { res |= BTN_SW3; } return res; }
/***************************************************************************** ** Function name: user_switch_init ** ** Descriptions: Initialize external interrupt pin and ** install interrupt handler ** ** parameters: None ** Returned value: true or false, return false if the interrupt ** handler can't be installed to the VIC table. ** *****************************************************************************/ void user_switch_init( void ) { GPIO_SetDir(1, 1<<25,0); if(!(GPIO_ReadValue(1)&1<<25)) { int_flag=1; } else { int_flag = 0; } }
// Таймаут задается в миллисекундах Status W_Wait(uint32_t Delay) { uint32_t Port; Timer0_Start(Delay); while (!Timer0_Status()) { Port = GPIO_ReadValue(WAIT_PORT); if (!(Port & (1<<WAIT_PIN))) { Timer0_Stop(); return SUCCESS; } else { Port = 0; } } Timer0_Stop(); return ERROR; }
// from sbl_iap BOOL bootloader_button_pressed(void) { /* Configure bootloader IO button P4.29 */ PINSEL_CFG_Type pin; pin.Portnum = 4; pin.Pinnum = 29; pin.Funcnum = PINSEL_FUNC_0; pin.Pinmode = PINSEL_PINMODE_PULLUP; pin.OpenDrain = PINSEL_PINMODE_NORMAL; PINSEL_ConfigPin(&pin); /* set as input */ GPIO_SetDir(4, (1<<29), 0); /* Verify if bootloader pin is activated */ if(GPIO_ReadValue(4) & (1<<29)) return FALSE; return TRUE; }
//------------------------------------------------------------------------------------------------------- //函数名称: GPIO_ReadIoVal() //功 能: 读取引脚上值 //入口参数: GpioNum: 引脚编号,由端口*100+ 引脚编号 组成。 //出口参数: 0 或1 //作 者: redmorningcn //日 期: 2017-05-15 //出口参数: 无 //说明: //-------------------------------------------------------------------------------------------------------- uint8 GPIO_ReadIoVal(uint32_t GpioNum) { uint32 PortBuf[] = {PINSEL_PORT_0,PINSEL_PORT_1,PINSEL_PORT_2,PINSEL_PORT_3,PINSEL_PORT_4}; uint8 PortNum; uint8 IoNum; uint32 PortVal; PortNum = GpioNum/100; IoNum = GpioNum%100; GPIO_SetDir(PortBuf[PortNum], 0x01ul<<IoNum,0); PortVal = GPIO_ReadValue(PortBuf[PortNum]); if(PortVal & 1ul<<IoNum) { return 1; } return 0; }
void check_isp_entry_pin (void) { /* Configure bootloader IO button P4.29 */ PINSEL_CFG_Type pin; pin.Portnum = BOOT_BUTTON_PORT; pin.Pinnum = BOOT_BUTTON_PIN; pin.Funcnum = PINSEL_FUNC_0; pin.Pinmode = PINSEL_PINMODE_PULLUP; pin.OpenDrain = PINSEL_PINMODE_NORMAL; PINSEL_ConfigPin(&pin); /* set as input */ GPIO_SetDir(BOOT_BUTTON_PORT, (1<<BOOT_BUTTON_PIN), 0); /* Verify if bootloader pin is activated */ if(GPIO_ReadValue(BOOT_BUTTON_PORT) & (1<<BOOT_BUTTON_PIN)) { execute_user_code(); } }
//==================== Управление сигналом CS0 с анализом сигнала WAIT====== void CS_Force_WAIT(uint32_t state) { //TODO Анализ сигнала WAIT uint32_t dwPortStatus; uint32_t tmp; dwPortStatus = GPIO_ReadValue(0); // считать данные из 0 порта, получить значение выходов порта 0 if (state){ // Перед убиранием CS дадим крипто принять последний байт посылки for (tmp = 50; tmp; tmp--); while(dwPortStatus & (1<<WAIT_PIN)) {/*NOP*/} //Если WAIT_SIG=HI(неактивный уровень), то не нужно устанавливать сигнал SS(CS0), нужно ждать GPIO_SetValue(0, (1<<16)); } else { GPIO_ClearValue(0, (1<<16)); for (tmp = 50; tmp; tmp--); // После сыставления CS в 0 дадим крипто это увидеть и перейти к приему // первого байта } }
/*********************************************************************//** * @brief Detects pressed Key * @param[in] None * @return Key Value **********************************************************************/ uchar Detect_Key (void) { uint32_t x; x = GPIO_ReadValue(0); // Read Port0 Pin state and store in x x |= 0xff87ffff; // Now make all pins 1 except Key Pins if(x ==(0xfff7ffff)) // check if Pin 0.19 is zero { return(1); } else if(x ==(0xffefffff)) // check if Pin 0.20 is zero { return(2); } else if(x ==(0xffdfffff)) // check if Pin 0.21 is zero { return(3); } else if(x ==(0xffbfffff)) // check if Pin 0.22 is zero { return(4); } return(0); }
int main(void) { FATFS FatFs; /* Work area (file system object) for logical drive */ FIL fil; /* File object */ bool stats = false; char line; /* Line buffer */ PINSEL_CFG_Type PinCfg; PinCfg.OpenDrain = PINSEL_PINMODE_NORMAL; PinCfg.Pinmode = PINSEL_PINMODE_PULLUP; PinCfg.Funcnum = 1; /* We need to use this because SSEL is made outside. */ PinCfg.Pinnum = 23; PINSEL_ConfigPin(&PinCfg); GPIO_SetDir(1, (1 << 23), 0); SystemInit(); SystemCoreClockUpdate(); if(f_mount(&FatFs, "", 1) == FR_OK) { DEBUGP("\nMounted!"); if(f_open(&fil, "logger.txt", (FA_OPEN_ALWAYS | FA_READ | FA_WRITE)) == FR_OK) { DEBUGP("\nOpened!"); } } else { DEBUGP("\nError!"); } // Byte Read Allocation. // FRESULT fr; /* FatFs function common result code */ // UINT br, bw; /* File read/write count */ // for (;;) /* For test from f_read only. */ // { // fr = f_read(&fil, &line, 1, &br); /* Read a chunk of byte of source file */ // if (fr || br == 0) break; /* error or eof */ // printf("%c", line); // } // Character Read Allocation. // f_gets(&line, sizeof(line), &fil); /* Read a chunk of character of source file */ while(1) { if((GPIO_ReadValue(1) & (1 << 23)) && (stats == false)) { stats = true; // if(f_write(&fil, "Button Enabled!", 17, &bw) == FR_OK) // error if(f_puts("\nButton Enabled!", &fil) != 0) // error { f_sync(&fil); DEBUGP("\nWritted and Enabled!"); } } if(!(GPIO_ReadValue(1) & (1 << 23)) && (stats == true)) { stats = false; // if(f_write(&fil, "Button Disabled!\r\n", 18, &bw) == FR_OK) if(f_puts("\nButton Disabled!", &fil) != 0) { f_sync(&fil); DEBUGP("\nWritted and Disabled!"); } } } }
void LED_Toggle(LED_STRUCT led) { bool lsts = GPIO_ReadValue(led.port)&led.pin; LED_SetValue(led, lsts); }
void TIMER0_IRQHandler(void) { static signed int comodin = 10; //Se usa comodin para dar el valor inicial //ya que se debe asignar un valor fijo al momento de //compilación.- static signed int valor_relativo = 0; //Almacenará el valor del timer capturado cuando interrumpe static signed int valor_absoluto = 0; //Almacenará el valor en useg acumulados entre flancos static signed int cero = 0; //Es el cero que tomará el valor final del nivel anterior if (habilitacion==TRUE){ //Estoy habilitado para operar? if (comodin==10){ cero = TIM_GetCaptureValue(LPC_TIM0,0); //Es la primera vez? comodin=20; //Cambio el valor para no volver } valor_relativo=TIM_GetCaptureValue(LPC_TIM0,0); //Copio el valor del timer capturado valor_absoluto=valor_relativo-cero; //Me quedo con el valor absolito de tiempo en useg if (valor_absoluto>MAX_FULL_BIT) //Me fijo si ese valor está fuera del valor máximo según norma { //Si era mayor es un error. Acá puede caer, si por ejemplo sys = 0; //habilito la medición y decodificación y justo cae en medio cmd = 0; //de un código. } if (GPIO_ReadValue(0) & (1<<24)) // Chequeo el GPIO P0.24 para ver que tipo de flanco es { if (sys == 0) // Es el primer pulso? { low_time = HALF_BIT_TIME; // Asumo tiempo corto en nivel bajo high_time = HALF_BIT_TIME; // Asumo tiempo corto en nivel alto half_bit = 1; // Asumo que es la mitad de un bit cmd = 0x02; // = 00000010, Preparo el byte del comando } else { low_time = valor_absoluto; // Es flanco positivo, copio valor bajo } RC5_Decode(); } else high_time = valor_absoluto; //Sino en flanco negativo, copio valor alto cero=valor_relativo; //El valor del final del nivel (alto o bajo) será mi nuevo cero TIM_ClearIntCapturePending(LPC_TIM0,0); //Reseteo la interrupción } if (habilitacion==FALSE){ //Si estoy acá, estoy en el tiempo donde no habilito la , //edición y decodificación. Lo hago para que no detecte muchos pulsos //en un pulsado. valor_relativo=TIM_GetCaptureValue(LPC_TIM0,0); //Analizo cuanto tiempo pasó desde el último valor_absoluto=valor_relativo-cero; //flanco. if (valor_absoluto>RETARDO) //Si es mayor a RETARDO useg { habilitacion=TRUE; //Ya pasó el tiempo de resguardo cero=valor_relativo; //Actualizo el cero TIM_ClearIntCapturePending(LPC_TIM0,0); //Reseteo interrupción } else TIM_ClearIntCapturePending(LPC_TIM0,0); //Si no pasó el tiempo sólo reseteo interrupción } }
unsigned int GetKey(void) { return !((GPIO_ReadValue(2)&KEY1_PAD)); }
uint8_t hw_digital_read ( size_t ulPin ) { uint32_t res = GPIO_ReadValue(g_APinDescription[ulPin].portNum); return (res & (1<<g_APinDescription[ulPin].bitNum)) != 0 ? 1 : 0; }
/* Private: Detect if USB VBUS is active. * * This isn't useful if there's no diode between an external 12v/9v power supply * (e.g. vehicle power from OBD-II) and the 5v rail, because then VBUS high when * the power is powered on regardless of the status of USB. In that situation, * you can fall back to the usbHostDetected() function instead. * * Returns true if VBUS is high. */ bool vbusDetected() { return (GPIO_ReadValue(VBUS_PORT) & (1 << VBUS_PIN)) != 0; }
/** * @brief The same with GPIO_ReadValue() */ uint32_t FIO_ReadValue(uint8_t portNum) { return (GPIO_ReadValue(portNum)); }
bool LED_GetValue(LED_STRUCT led) { return GPIO_ReadValue(led.port)&led.pin; }