|
| 1 | +/**************************************************************************** |
| 2 | + * boards/arm64/a64/pinephone/src/pinephone_autoleds.c |
| 3 | + * |
| 4 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
| 5 | + * contributor license agreements. See the NOTICE file distributed with |
| 6 | + * this work for additional information regarding copyright ownership. The |
| 7 | + * ASF licenses this file to you under the Apache License, Version 2.0 (the |
| 8 | + * "License"); you may not use this file except in compliance with the |
| 9 | + * License. You may obtain a copy of the License at |
| 10 | + * |
| 11 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | + * |
| 13 | + * Unless required by applicable law or agreed to in writing, software |
| 14 | + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 15 | + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 16 | + * License for the specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + * |
| 19 | + ****************************************************************************/ |
| 20 | + |
| 21 | +/**************************************************************************** |
| 22 | + * Included Files |
| 23 | + ****************************************************************************/ |
| 24 | + |
| 25 | +#include <nuttx/config.h> |
| 26 | + |
| 27 | +#include <stdint.h> |
| 28 | +#include <stdbool.h> |
| 29 | +#include <debug.h> |
| 30 | + |
| 31 | +#include <sys/param.h> |
| 32 | + |
| 33 | +#include <nuttx/board.h> |
| 34 | +#include <arch/board/board.h> |
| 35 | + |
| 36 | +#include "chip.h" |
| 37 | +////#include "arm64_internal.h" |
| 38 | +////#include "pinephone.h" |
| 39 | + |
| 40 | +#ifdef CONFIG_ARCH_LEDS |
| 41 | + |
| 42 | +/**************************************************************************** |
| 43 | + * Private Data |
| 44 | + ****************************************************************************/ |
| 45 | + |
| 46 | +/* LED index */ |
| 47 | + |
| 48 | +// static const uint32_t g_led_map[BOARD_LEDS] = |
| 49 | +// { |
| 50 | +// LED1, |
| 51 | +// LED2, |
| 52 | +// LED3 |
| 53 | +// }; |
| 54 | + |
| 55 | +static bool g_initialized; |
| 56 | + |
| 57 | +/**************************************************************************** |
| 58 | + * Private Functions |
| 59 | + ****************************************************************************/ |
| 60 | + |
| 61 | +/* Turn on selected led */ |
| 62 | + |
| 63 | +static void bl808_led_on(led_typedef_enum led_num) |
| 64 | +{ |
| 65 | + ////TODO: gpio_write(g_led_map[led_num], true); |
| 66 | +} |
| 67 | + |
| 68 | +/* Turn off selected led */ |
| 69 | + |
| 70 | +static void bl808_led_off(led_typedef_enum led_num) |
| 71 | +{ |
| 72 | + ////TODO: gpio_write(g_led_map[led_num], false); |
| 73 | +} |
| 74 | + |
| 75 | +/**************************************************************************** |
| 76 | + * Public Functions |
| 77 | + ****************************************************************************/ |
| 78 | + |
| 79 | +/**************************************************************************** |
| 80 | + * Name: board_autoled_initialize |
| 81 | + * |
| 82 | + * Description: |
| 83 | + * This function is called very early in initialization to perform board- |
| 84 | + * specific initialization of LED-related resources. This includes such |
| 85 | + * things as, for example, configure GPIO pins to drive the LEDs and also |
| 86 | + * putting the LEDs in their correct initial state. |
| 87 | + * |
| 88 | + * NOTE: In most architectures, board_autoled_initialize() is called from |
| 89 | + * board-specific initialization logic. But there are a few architectures |
| 90 | + * where this initialization function is still called from common chip |
| 91 | + * architecture logic. This interface is not, however, a common board |
| 92 | + * interface in any event and, hence, the usage of the name |
| 93 | + * board_autoled_initialize is deprecated. |
| 94 | + * |
| 95 | + * WARNING: This interface name will eventually be removed; do not use it |
| 96 | + * in new board ports. New implementations should use the naming |
| 97 | + * conventions for "Microprocessor-Specific Interfaces" or the "Board- |
| 98 | + * Specific Interfaces" as described above. |
| 99 | + * |
| 100 | + * Input Parameters: |
| 101 | + * None |
| 102 | + * |
| 103 | + * Returned Value: |
| 104 | + * None |
| 105 | + * |
| 106 | + ****************************************************************************/ |
| 107 | + |
| 108 | +void board_autoled_initialize(void) |
| 109 | +{ |
| 110 | + int i; |
| 111 | + |
| 112 | + /* Configure the LED GPIO for output. */ |
| 113 | + |
| 114 | + for (i = 0; i < BOARD_LEDS; i++) |
| 115 | + { |
| 116 | + ////TODO: int ret = gpio_config(g_led_map[i]); |
| 117 | + ////TODO: DEBUGASSERT(ret == OK); |
| 118 | + } |
| 119 | +} |
| 120 | + |
| 121 | +/**************************************************************************** |
| 122 | + * Name: board_autoled_on |
| 123 | + * |
| 124 | + * Description: |
| 125 | + * Set the LED configuration into the ON condition for the state provided |
| 126 | + * by the led parameter. This may be one of: |
| 127 | + * |
| 128 | + * LED_STARTED NuttX has been started |
| 129 | + * LED_HEAPALLOCATE Heap has been allocated |
| 130 | + * LED_IRQSENABLED Interrupts enabled |
| 131 | + * LED_STACKCREATED Idle stack created |
| 132 | + * LED_INIRQ In an interrupt |
| 133 | + * LED_SIGNAL In a signal handler |
| 134 | + * LED_ASSERTION An assertion failed |
| 135 | + * LED_PANIC The system has crashed |
| 136 | + * LED_IDLE MCU is in sleep mode |
| 137 | + * |
| 138 | + * Where these values are defined in a board-specific way in the standard |
| 139 | + * board.h header file exported by every architecture. |
| 140 | + * |
| 141 | + * Input Parameters: |
| 142 | + * led - Identifies the LED state to put in the ON state (which may or may |
| 143 | + * not equate to turning an LED on) |
| 144 | + * |
| 145 | + * Returned Value: |
| 146 | + * None |
| 147 | + * |
| 148 | + ****************************************************************************/ |
| 149 | + |
| 150 | +void board_autoled_on(int led) |
| 151 | +{ |
| 152 | + switch (led) |
| 153 | + { |
| 154 | + case LED_HEAPALLOCATE: |
| 155 | + bl808_led_on(BOARD_LED1); |
| 156 | + break; |
| 157 | + |
| 158 | + case LED_IRQSENABLED: |
| 159 | + bl808_led_on(BOARD_LED2); |
| 160 | + break; |
| 161 | + |
| 162 | + case LED_STACKCREATED: |
| 163 | + bl808_led_on(BOARD_LED3); |
| 164 | + g_initialized = true; |
| 165 | + break; |
| 166 | + |
| 167 | + case LED_INIRQ: |
| 168 | + bl808_led_on(BOARD_LED1); |
| 169 | + bl808_led_on(BOARD_LED2); |
| 170 | + break; |
| 171 | + |
| 172 | + case LED_SIGNAL: |
| 173 | + bl808_led_on(BOARD_LED1); |
| 174 | + bl808_led_on(BOARD_LED3); |
| 175 | + break; |
| 176 | + |
| 177 | + case LED_ASSERTION: |
| 178 | + bl808_led_on(BOARD_LED2); |
| 179 | + bl808_led_on(BOARD_LED3); |
| 180 | + break; |
| 181 | + |
| 182 | + case LED_PANIC: |
| 183 | + bl808_led_on(BOARD_LED1); |
| 184 | + break; |
| 185 | + |
| 186 | + case LED_IDLE: |
| 187 | + bl808_led_on(BOARD_LED2); |
| 188 | + break; |
| 189 | + |
| 190 | + default: |
| 191 | + break; |
| 192 | + } |
| 193 | +} |
| 194 | + |
| 195 | +/**************************************************************************** |
| 196 | + * Name: board_autoled_off |
| 197 | + * |
| 198 | + * Description: |
| 199 | + * Set the LED configuration into the OFF condition for the state provided |
| 200 | + * by the led parameter. This may be one of: |
| 201 | + * |
| 202 | + * LED_INIRQ Leaving an interrupt |
| 203 | + * LED_SIGNAL Leaving a signal handler |
| 204 | + * LED_ASSERTION Recovering from an assertion failure |
| 205 | + * LED_PANIC The system has crashed (blinking). |
| 206 | + * LED_IDLE MCU is not in sleep mode |
| 207 | + * |
| 208 | + * Where these values are defined in a board-specific way in the standard |
| 209 | + * board.h header file exported by every architecture. |
| 210 | + * |
| 211 | + * Input Parameters: |
| 212 | + * led - Identifies the LED state to put in the OFF state (which may or may |
| 213 | + * not equate to turning an LED off) |
| 214 | + * |
| 215 | + * Returned Value: |
| 216 | + * None |
| 217 | + * |
| 218 | + ****************************************************************************/ |
| 219 | + |
| 220 | +void board_autoled_off(int led) |
| 221 | +{ |
| 222 | + switch (led) |
| 223 | + { |
| 224 | + case LED_SIGNAL: |
| 225 | + bl808_led_off(BOARD_LED1); |
| 226 | + bl808_led_off(BOARD_LED3); |
| 227 | + break; |
| 228 | + |
| 229 | + case LED_INIRQ: |
| 230 | + bl808_led_off(BOARD_LED1); |
| 231 | + bl808_led_off(BOARD_LED2); |
| 232 | + break; |
| 233 | + |
| 234 | + case LED_ASSERTION: |
| 235 | + bl808_led_off(BOARD_LED2); |
| 236 | + bl808_led_off(BOARD_LED3); |
| 237 | + break; |
| 238 | + |
| 239 | + case LED_PANIC: |
| 240 | + bl808_led_off(BOARD_LED1); |
| 241 | + break; |
| 242 | + |
| 243 | + case LED_IDLE: |
| 244 | + bl808_led_off(BOARD_LED2); |
| 245 | + break; |
| 246 | + |
| 247 | + default: |
| 248 | + break; |
| 249 | + } |
| 250 | +} |
| 251 | + |
| 252 | +#endif /* CONFIG_ARCH_LEDS */ |
0 commit comments