2015-12-15 21:10:21 +01:00
|
|
|
/****************************************************************************
|
2021-06-16 09:22:16 +02:00
|
|
|
* apps/examples/pca9635/pca9635_main.c
|
2015-12-15 21:10:21 +01:00
|
|
|
*
|
2021-06-15 09:09:58 +02:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2015-12-15 21:10:21 +01:00
|
|
|
*
|
2021-06-15 09:09:58 +02:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2015-12-15 21:10:21 +01:00
|
|
|
*
|
2021-06-15 09:09:58 +02:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2015-12-15 21:10:21 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2019-04-28 13:33:21 +02:00
|
|
|
#include <nuttx/leds/pca9635pw.h>
|
2015-12-15 21:10:21 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Pre-processor Definitions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#define CONFIG_EXAMPLES_PCA9635_DEVNAME "/dev/leddrv0"
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* pca9635_main
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int main(int argc, FAR char *argv[])
|
|
|
|
{
|
2020-06-12 22:22:02 +02:00
|
|
|
struct pca9635pw_brightness_s ledbright;
|
2015-12-15 21:10:21 +01:00
|
|
|
int led;
|
|
|
|
int bright;
|
|
|
|
int fd;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
fd = open(CONFIG_EXAMPLES_PCA9635_DEVNAME, O_RDONLY);
|
|
|
|
if (fd < 0)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "ERROR: Failed to open %s: %d\n",
|
|
|
|
CONFIG_EXAMPLES_PCA9635_DEVNAME, errno);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (; ; )
|
|
|
|
{
|
|
|
|
for (bright = 0; bright <= 255; bright++)
|
|
|
|
{
|
|
|
|
for (led = LED_0; led <= LED_15; led++)
|
|
|
|
{
|
|
|
|
ledbright.led = led;
|
|
|
|
ledbright.brightness = bright;
|
|
|
|
|
2020-06-12 22:22:02 +02:00
|
|
|
ret = ioctl(fd, PWMIOC_SETLED_BRIGHTNESS,
|
|
|
|
(unsigned long)&ledbright);
|
2015-12-15 21:10:21 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
2020-06-12 22:22:02 +02:00
|
|
|
_err("ERROR: ioctl(PWMIOC_SETLED_BRIGHTNESS) failed: %d\n",
|
|
|
|
errno);
|
2015-12-15 21:10:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
usleep(100);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
close(fd);
|
|
|
|
return 0;
|
2019-04-28 13:33:21 +02:00
|
|
|
}
|