示例#1
0
static void _touch(void *p)
{
    int io_s;

    gpio_pin_config_t pin_config =
    {
        kGPIO_DigitalInput, 0,
    };

    CLOCK_EnableClock(kCLOCK_Gpio4);

    /* Enable touch panel controller */
    GPIO_PinInit(GPIO, 4, 0, &pin_config);

    while(1)
    {
        rt_thread_delay(RT_TICK_PER_SECOND / 60);

        io_s = GPIO_ReadPinInput(GPIO, 4, 0);
        if (io_s == 0)
        {
            _touch_session();
        }
        else
            continue;
    }
}
示例#2
0
int gpio_read(gpio_t *obj)
{
    MBED_ASSERT(obj->pin != (PinName)NC);
    uint32_t pin_number = obj->pin & 0x1F;
    uint8_t port_number = obj->pin / 32;

    return (int)GPIO_ReadPinInput(GPIO, port_number, pin_number);
}
示例#3
0
void PORTC_IRQHandler(void)
{
	if (GPIO_ReadPinInput(NXPNCI_IRQ_GPIO, NXPNCI_IRQ_PIN) == 1)
	{
	    BaseType_t xHigherPriorityTaskWoken = pdFALSE;
		GPIO_ClearPinsInterruptFlags(NXPNCI_IRQ_GPIO, 1U << NXPNCI_IRQ_PIN);
		xSemaphoreGiveFromISR(IrqSem, &xHigherPriorityTaskWoken);
	}
}
示例#4
0
static int imx_gpio_read(struct device *dev,
			  int access_op, u32_t pin, u32_t *value)
{
	const struct imx_gpio_config *config = dev->config->config_info;

	if (access_op == GPIO_ACCESS_BY_PIN) {
		*value = GPIO_ReadPinInput(config->base, pin);
	} else { /* GPIO_ACCESS_BY_PORT */
		*value = GPIO_ReadPortInput(config->base);
	}

	return 0;
}
/* Card detect interrupt handler. */
void DetectCardByGpio(void)
{
    if (GPIO_ReadPinInput(BOARD_SDHC_CD_GPIO_BASE, BOARD_SDHC_CD_GPIO_PIN))
#if defined BOARD_SDHC_CD_LOGIC_RISING
    {
        g_sdInsertedFlag = 1U;
    }
    else
    {
        g_sdInsertedFlag = 0U;
    }
#else
    {
        g_sdInsertedFlag = 0U;
    }
    else
    {
int test_sdhc(void) {
#if TEST_SDCARD
  if(CLOCK_GetBusClkFreq() < SD_CLOCK_25MHZ) {
    PRINT("skipping SDHC test, bus clock frequency %d is lower than required %d\r\n",CLOCK_GetBusClkFreq(), SD_CLOCK_25MHZ);
    return;
  }

  init_sdhc_pins();

  FRESULT error;
  DIR directory; /* Directory object */
  FILINFO fileInformation;
  UINT bytesWritten;
  UINT bytesRead;
  const TCHAR driverNumberBuffer[3U] = {SDDISK + '0', ':', '/'};

  MPU_Enable(MPU, false);

  PRINTF("\r\nFATFS example to demonstrate how to use FATFS with SD card.\r\n");

  PRINTF("\r\nPlease insert a card into board.\r\n");

  /* Wait the card to be inserted. */
  while (!(GPIO_ReadPinInput(GPIOE, 7U))) {
  }
  PRINTF("Detected SD card inserted.\r\n");
  /* Delat some time to make card stable. */
  delay(1000U);

  if (f_mount(&g_fileSystem, driverNumberBuffer, 0U)) {
    PRINTF("Mount volume failed.\r\n");
    return -1;
  }

#if (_FS_RPATH >= 2U)
  error = f_chdrive(&driverNumberBuffer[0U]);
  if (error) {
    PRINTF("Change drive failed.\r\n");
    return -1;
  }
#endif

#if _USE_MKFS
  PRINTF("\r\nMake file system......The time may be long if the card capacity is big.\r\n");
if (f_mkfs(driverNumberBuffer, 1U, 0U))
{
    PRINTF("Make file system failed.\r\n");
    return -1;
}
#endif /* _USE_MKFS */

  FIL testFileObject;
  PRINTF("\r\nRead from static test file\r\n");
  error = f_open(&testFileObject, _T("/test.txt"), FA_READ);
  if (error) {
    PRINTF("Open file failed (%d).\r\n", error);
    return -1;
  }

  memset(g_bufferRead, 0U, sizeof(g_bufferRead));
  error = f_read(&testFileObject, g_bufferRead, sizeof(g_bufferRead), &bytesRead);
  if (error) {
    PRINTF("Read file failed. \r\n");
  }
  PRINTF("bytes read: %d\r\n", bytesRead);
  PRINTF("----\r\n");
  PRINTF("%s", g_bufferRead);
  PRINTF("----\r\n");


  if (f_close(&testFileObject)) {
    PRINTF("\r\nClose file failed.\r\n");
    return -1;
  }

  PRINTF("\r\nCreate directory......\r\n");
  error = f_mkdir(_T("/dir_1"));
  if (error) {
    if (error == FR_EXIST) {
      PRINTF("Directory exists.\r\n");
    } else {
      PRINTF("Make directory failed.\r\n");
      return -1;
    }
  }

  PRINTF("\r\nCreate a file in that directory......\r\n");
  error = f_open(&g_fileObject, _T("/dir_1/f_1.dat"), (FA_WRITE | FA_READ | FA_CREATE_ALWAYS));
  if (error) {
    if (error == FR_EXIST) {
      PRINTF("File exists.\r\n");
    } else {
      PRINTF("Open file failed.\r\n");
      return -1;
    }
  }

  PRINTF("\r\nCreate a directory in that directory......\r\n");
  error = f_mkdir(_T("/dir_1/dir_2"));
  if (error) {
    if (error == FR_EXIST) {
      PRINTF("Directory exists.\r\n");
    } else {
      PRINTF("Directory creation failed.\r\n");
      return -1;
    }
  }

  PRINTF("\r\nList the file in that directory......\r\n");
  if (f_opendir(&directory, "/dir_1")) {
    PRINTF("Open directory failed.\r\n");
    return -1;
  }

  for (;;) {
    error = f_readdir(&directory, &fileInformation);

    /* To the end. */
    if ((error != FR_OK) || (fileInformation.fname[0U] == 0U)) {
      break;
    }
    if (fileInformation.fname[0] == '.') {
      continue;
    }
    if (fileInformation.fattrib & AM_DIR) {
      PRINTF("Directory file : %s.\r\n", fileInformation.fname);
    } else {
      PRINTF("General file : %s.\r\n", fileInformation.fname);
    }
  }

  memset(g_bufferWrite, 'a', sizeof(g_bufferWrite));
  g_bufferWrite[BUFFER_SIZE - 2U] = '\r';
  g_bufferWrite[BUFFER_SIZE - 1U] = '\n';

  PRINTF("\r\nWrite/read file ...\r\n");

  PRINTF("\r\nWrite to above created file.\r\n");
  error = f_write(&g_fileObject, g_bufferWrite, sizeof(g_bufferWrite), &bytesWritten);
  if ((error) || (bytesWritten != sizeof(g_bufferWrite))) {
    PRINTF("Write file failed. \r\n");
    return -1;
  }

  /* Move the file pointer */
  if (f_lseek(&g_fileObject, 0U)) {
    PRINTF("Set file pointer position failed. \r\n");
    return -1;
  }

  PRINTF("Read from above created file.\r\n");
  memset(g_bufferRead, 0U, sizeof(g_bufferRead));
  error = f_read(&g_fileObject, g_bufferRead, sizeof(g_bufferRead), &bytesRead);
  if ((error) || (bytesRead != sizeof(g_bufferRead))) {
    PRINTF("Read file failed. \r\n");
    return -1;
  }

  PRINTF("Compare the read/write content......\r\n");
  if (memcmp(g_bufferWrite, g_bufferRead, sizeof(g_bufferWrite))) {
    PRINTF("Compare read/write content isn't consistent.\r\n");
    return -1;
  }
  PRINTF("The read/write content is consistent.\r\n");


  PRINTF("\r\nThe example will not read/write file again.\r\n");

  if (f_close(&g_fileObject)) {
    PRINTF("\r\nClose file failed.\r\n");
    return -1;
  }

#endif
  return 0;
}
示例#7
0
static bool SW3IsPressed(void) {
  return GPIO_ReadPinInput(GPIOB, 17u)==0; /* SW3 on PTB17 */
}
示例#8
0
static bool SW2IsPressed(void) {
  return GPIO_ReadPinInput(GPIOC, 1u)==0; /* SW2 on PTC1 */
}
示例#9
0
int
hal_gpio_read(int pin)
{
    return (int)GPIO_ReadPinInput(s_gpioBases[GPIO_PORT(pin)], GPIO_INDEX(pin));
}