board_api.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. /*
  2. * @brief Common board API functions
  3. *
  4. * @note
  5. * Copyright(C) NXP Semiconductors, 2013
  6. * All rights reserved.
  7. *
  8. * @par
  9. * Software that is described herein is for illustrative purposes only
  10. * which provides customers with programming information regarding the
  11. * LPC products. This software is supplied "AS IS" without any warranties of
  12. * any kind, and NXP Semiconductors and its licensor disclaim any and
  13. * all warranties, express or implied, including all implied warranties of
  14. * merchantability, fitness for a particular purpose and non-infringement of
  15. * intellectual property rights. NXP Semiconductors assumes no responsibility
  16. * or liability for the use of the software, conveys no license or rights under any
  17. * patent, copyright, mask work right, or any other intellectual property rights in
  18. * or to any products. NXP Semiconductors reserves the right to make changes
  19. * in the software without notification. NXP Semiconductors also makes no
  20. * representation or warranty that such application will be suitable for the
  21. * specified use without further testing or modification.
  22. *
  23. * @par
  24. * Permission to use, copy, modify, and distribute this software and its
  25. * documentation is hereby granted, under NXP Semiconductors' and its
  26. * licensor's relevant copyrights in the software, without fee, provided that it
  27. * is used in conjunction with NXP Semiconductors microcontrollers. This
  28. * copyright, permission, and disclaimer notice must appear in all copies of
  29. * this code.
  30. */
  31. #ifndef __BOARD_API_H_
  32. #define __BOARD_API_H_
  33. #include "lpc_types.h"
  34. #include <stdio.h>
  35. #ifdef __cplusplus
  36. extern "C" {
  37. #endif
  38. /** @defgroup BOARD_COMMON_API BOARD: Common board functions
  39. * @ingroup BOARD_Common
  40. * This file contains common board definitions that are shared across
  41. * boards and devices. All of these functions do not need to be
  42. * implemented for a specific board, but if they are implemented, they
  43. * should use this API standard.
  44. * @{
  45. */
  46. /**
  47. * @brief Setup and initialize hardware prior to call to main()
  48. * @return None
  49. * @note Board_SystemInit() is called prior to the application and sets up system
  50. * clocking, memory, and any resources needed prior to the application
  51. * starting.
  52. */
  53. void Board_SystemInit(void);
  54. /**
  55. * @brief Setup pin multiplexer per board schematics
  56. * @return None
  57. * @note Board_SetupMuxing() should be called from SystemInit() prior to application
  58. * main() is called. So that the PINs are set in proper state.
  59. */
  60. void Board_SetupMuxing(void);
  61. /**
  62. * @brief Setup system clocking
  63. * @return None
  64. * @note This sets up board clocking.
  65. */
  66. void Board_SetupClocking(void);
  67. /**
  68. * @brief Setup external system memory
  69. * @return None
  70. * @note This function is typically called after pin mux setup and clock setup and
  71. * sets up any external memory needed by the system (DRAM, SRAM, etc.). Not all
  72. * boards need this function.
  73. */
  74. void Board_SetupExtMemory(void);
  75. /**
  76. * @brief Set up and initialize all required blocks and functions related to the board hardware.
  77. * @return None
  78. */
  79. void Board_Init(void);
  80. /**
  81. * @brief Initializes board UART for output, required for printf redirection
  82. * @return None
  83. */
  84. void Board_Debug_Init(void);
  85. /**
  86. * @brief Sends a single character on the UART, required for printf redirection
  87. * @param ch : character to send
  88. * @return None
  89. */
  90. void Board_UARTPutChar(char ch);
  91. /**
  92. * @brief Sends a single character on the UART, automatic process '\n' -> '\r\n'
  93. * @param ch : character to send
  94. * @return None
  95. */
  96. void Board_UARTPutTextChar(char ch);
  97. /**
  98. * @brief Classic implementation of itoa -- integer to ASCII
  99. * @param value : value to convert
  100. * @param result : result string
  101. * @param base : output radix
  102. * @return result string or NULL
  103. */
  104. char *Board_itoa(int value, char *result, int base);
  105. /**
  106. * @brief Get a single character from the UART, required for scanf input
  107. * @return EOF if not character was received, or character value
  108. */
  109. int Board_UARTGetChar(void);
  110. /**
  111. * @brief Prints a string to the UART
  112. * @param str : Terminated string to output
  113. * @return None
  114. */
  115. void Board_UARTPutSTR(const char *str);
  116. /**
  117. * @brief Get if a key is down
  118. * @param keyIndex : The index of the key to detect
  119. * @return 1 = key is down , 0 = key is up
  120. */
  121. uint32_t Board_Key_GetKeyDown(uint32_t keyIndex);
  122. /**
  123. * @brief Sets the state of a board LED to on or off
  124. * @param LEDNumber : LED number to set state for
  125. * @param State : true for on, false for off
  126. * @return None
  127. */
  128. void Board_LED_Set(uint8_t LEDNumber, bool State);
  129. /**
  130. * @brief Returns the current state of a board LED
  131. * @param LEDNumber : LED number to set state for
  132. * @return true if the LED is on, otherwise false
  133. */
  134. bool Board_LED_Test(uint8_t LEDNumber);
  135. /**
  136. * @brief Toggles the current state of a board LED
  137. * @param LEDNumber : LED number to change state for
  138. * @return None
  139. */
  140. void Board_LED_Toggle(uint8_t LEDNumber);
  141. /**
  142. * @brief Turn on Board LCD Backlight
  143. * @param Intensity : Backlight intensity (0 = off, >=1 = on)
  144. * @return None
  145. * @note On boards where a GPIO is used to control backlight on/off state, a '0' or '1'
  146. * value will turn off or on the backlight. On some boards, a non-0 value will
  147. * control backlight intensity via a PWN. For PWM systems, the intensity value
  148. * is a percentage value between 0 and 100%.
  149. */
  150. void Board_SetLCDBacklight(uint8_t Intensity);
  151. /**
  152. * @brief Function prototype for a MS delay function. Board layers or example code may
  153. * define this function as needed.
  154. */
  155. typedef void (*p_msDelay_func_t)(uint32_t);
  156. /* The DEBUG* functions are selected based on system configuration.
  157. Code that uses the DEBUG* functions will have their I/O routed to
  158. the UART, semihosting, or nowhere. */
  159. #if defined(DEBUG_ENABLE)
  160. #if defined(DEBUG_SEMIHOSTING)
  161. #define DEBUGINIT()
  162. #define DEBUGOUT(...) printf(__VA_ARGS__)
  163. #define DEBUGSTR(str) printf(str)
  164. #define DEBUGIN() (int) EOF
  165. #else
  166. #define DEBUGINIT() Board_Debug_Init()
  167. #define DEBUGOUT(...) printf(__VA_ARGS__)
  168. #define DEBUGSTR(str) Board_UARTPutSTR(str)
  169. #define DEBUGIN() Board_UARTGetChar()
  170. #endif /* defined(DEBUG_SEMIHOSTING) */
  171. #else
  172. #define DEBUGINIT()
  173. #define DEBUGOUT(...)
  174. #define DEBUGSTR(str)
  175. #define DEBUGIN() (int) EOF
  176. #endif /* defined(DEBUG_ENABLE) */
  177. /**
  178. * @}
  179. */
  180. #ifdef __cplusplus
  181. }
  182. #endif
  183. #endif /* __BOARD_API_H_ */