目次

LED の制御

XG-50 には、以下のとおり LED が実装されています。

XG-50 panel


シルク Note
PWR autoled として OS が制御
boardctl() 経由で制御
STS1 LED driver1) 経由で制御
STS2
STS3


POWER LED(緑) の制御

boardctl(BIOC_SET_LED) で 点灯/消灯 を制御します。

bool onoff = true;

boardctl(BIOC_SET_LED, (uintptr_t) onoff);


STATUS LED の制御

デフォルトの CONFIG では、LED driver として /dev/leddrv0 が登録されます。

nsh> ls -l /dev/
/dev:
 cr--r--r--       0 adc0
 crw-rw-rw-       0 console
 crw-rw-rw-       0 i2c1
 cr--r--r--       0 leddrv0  <----
 brw-rw-rw-       0 mtdblock0
 crw-rw-rw-       0 null
 crw-rw-rw-       0 ptmx
 crw-rw-rw-       0 ramlog
 cr--r--r--       0 random
 crw-rw-rw-       0 rtc0
 crw-rw-rw-       0 timer0
 crw-rw-rw-       0 ttyS0
 crw-rw-rw-       0 ttyS1
 crw-rw-rw-       0 ttyS2
 crw-rw-rw-       0 ttyS3
 crw-rw-rw-       0 zero
nsh> 


ioctl() により各 LED の ON/OFF を制御することができます。

<sxh c toolbar:false; title:led_main.c> #include <nuttx/config.h> #include <stdio.h> #include <fcntl.h> #include <sys/ioctl.h>

#include <nuttx/leds/tca6507.h>

int led_main(int argc, char argv) { int fd, ret = -1; struct tca6507_onoff_s leds; /* この構造体でリクエストを発行 */ fd = open(“/dev/leddrv0”, O_RDONLY); if (fd > 0) { leds.led = LED_STATUS3_GREEN; /* STATUS LED 3 の Green を */ leds.on = 1; /* 点灯させる */ ioctl(fd, LEDIOC_ONOFF, (intptr_t) &leds); close(fd); ret = 0; } return ret; } </sxh>
===== LED OFF Switch ===== 電池で駆動させる場合など、LED の消費電力が問題になるケースがあります。
そのような用途で、LED を強制的に
消灯**させるスイッチを用意してあります。

LED OFF Switch

スイッチを右側にスライドさせると、LED が全消灯となります。


Switch 状態の取得

boardctl() で LED OFF Switch の状態を取得することができます。

  int sw_state;

  boardctl(BIOC_GET_LEDSW, (uintptr_t) &sw_state); # sw_state == 0 --> LED OFF
1)
TCA6507