コード例 #1
0
ファイル: wpiExtensions.c プロジェクト: WiringPi/WiringPi
static int doExtensionMcp23s08 (char *progName, int pinBase, char *params)
{
  int spi, port ;

  if ((params = extractInt (progName, params, &spi)) == NULL)
    return FALSE ;

  if ((spi < 0) || (spi > 1))
  {
    verbError ("%s: SPI address (%d) out of range", progName, spi) ;
    return FALSE ;
  }

  if ((params = extractInt (progName, params, &port)) == NULL)
    return FALSE ;

  if ((port < 0) || (port > 7))
  {
    verbError ("%s: port address (%d) out of range", progName, port) ;
    return FALSE ;
  }

  mcp23s08Setup (pinBase, spi, port) ;

  return TRUE ;
}
コード例 #2
0
ファイル: gpio.c プロジェクト: Dzenik/WiringCB-python
static int doModuleMcp23s08 (char *progName, int pinBase, char *params)
{
  int spi, port ;

// Extract the SPI address:

  if (*params != ':')
  {
    fprintf (stderr, "%s: colon expected after pin-base number\n", progName) ;
    return FALSE ;
  }

  ++params ;
  if (!isdigit (*params))
  {
    fprintf (stderr, "%s: digit expected after pin-base number\n", progName) ;
    return FALSE ;
  }

  spi = *params - '0' ;
  if ((spi < 0) || (spi > 1))
  {
    fprintf (stderr, "%s: SPI address (%d) out of range\n", progName, spi) ;
    return FALSE ;
  }

// Extract the port:

  if (*++params != ':')
  {
    fprintf (stderr, "%s: colon expected after SPI address\n", progName) ;
    return FALSE ;
  }

  ++params ;
  if (!isdigit (*params))
  {
    fprintf (stderr, "%s: digit expected after SPI address\n", progName) ;
    return FALSE ;
  }

  port = strtol (params, NULL, 0) ;
  if ((port < 0) || (port > 7))
  {
    fprintf (stderr, "%s: port address (%d) out of range\n", progName, port) ;
    return FALSE ;
  }

  mcp23s08Setup (pinBase, spi, port) ;

  return TRUE ;
}