board_api.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /*
  2. * @brief Common board API functions
  3. *
  4. * @note
  5. * Copyright(C) NXP Semiconductors, 2012
  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. * impemented for a specific board, but if they are implemented, they
  43. * should use this API standard.
  44. * @{
  45. */
  46. /**
  47. * @brief Set up and initialize all required blocks and functions related to the board hardware.
  48. * @return None
  49. */
  50. void Board_Init(void);
  51. /**
  52. * @brief Initializes board UART for output, required for printf redirection
  53. * @return None
  54. */
  55. void Board_Debug_Init(void);
  56. /**
  57. * @brief Sends a single character on the UART, required for printf redirection
  58. * @param ch : character to send
  59. * @return None
  60. */
  61. void Board_UARTPutChar(char ch);
  62. /**
  63. * @brief Get a single character from the UART, required for scanf input
  64. * @return EOF if not character was received, or character value
  65. */
  66. int Board_UARTGetChar(void);
  67. /**
  68. * @brief Prints a string to the UART
  69. * @param str : Terminated string to output
  70. * @return None
  71. */
  72. void Board_UARTPutSTR(char *str);
  73. /**
  74. * @brief Initializes board LED(s)
  75. * @return None
  76. */
  77. void Board_LED_Init(void);
  78. /**
  79. * @brief Sets the state of a board LED to on or off
  80. * @param LEDNumber : LED number to set state for
  81. * @param State : true for on, false for off
  82. * @return None
  83. */
  84. void Board_LED_Set(uint8_t LEDNumber, bool State);
  85. /**
  86. * @brief Returns the current state of a board LED
  87. * @param LEDNumber : LED number to set state for
  88. * @return true if the LED is on, otherwise false
  89. */
  90. bool Board_LED_Test(uint8_t LEDNumber);
  91. /**
  92. * @brief Toggles the current state of a board LED
  93. * @param LEDNumber : LED number to change state for
  94. * @return None
  95. */
  96. STATIC INLINE void Board_LED_Toggle(uint8_t LEDNumber)
  97. {
  98. Board_LED_Set(LEDNumber, !Board_LED_Test(LEDNumber));
  99. }
  100. /**
  101. * @brief Current system clock rate, mainly used for sysTick
  102. */
  103. extern uint32_t SystemCoreClock;
  104. /**
  105. * @brief Update system core clock rate, should be called if the
  106. * system has a clock rate change
  107. * @return None
  108. */
  109. void SystemCoreClockUpdate(void);
  110. /**
  111. * @brief Turn on Board LCD Backlight
  112. * @param Intensity : Backlight intensity (0 = off, >=1 = on)
  113. * @return None
  114. * On boards where a GPIO is used to control backlight on/off state, a '0' or '1'
  115. * value will turn off or on the backlight. On some boards, a non-0 value will
  116. * control backlight intensity via a PWN. For PWM systems, the intensity value
  117. * is a percentage value between 0 and 100%.
  118. */
  119. void Board_LCD_Set_Backlight(uint8_t Intensity);
  120. /**
  121. * @brief Function prototype for a MS delay function. Board layers or example code may
  122. * define this function as needed.
  123. */
  124. typedef void (*p_msDelay_func_t)(uint32_t);
  125. /* The DEBUG* functions are selected based on system configuration.
  126. Code that uses the DEBUG* functions will have their I/O routed to
  127. the UART, semihosting, or nowhere. */
  128. #if defined(DEBUG)
  129. #if defined(DEBUG_SEMIHOSTING)
  130. #define DEBUGINIT()
  131. #define DEBUGOUT(...) printf(__VA_ARGS__)
  132. #define DEBUGSTR(str) printf(str)
  133. #define DEBUGIN() (int) EOF
  134. #else
  135. #define DEBUGINIT() Board_Debug_Init()
  136. #define DEBUGOUT(...) printf(__VA_ARGS__)
  137. #define DEBUGSTR(str) Board_UARTPutSTR(str)
  138. #define DEBUGIN() Board_UARTGetChar()
  139. #endif /* defined(DEBUG_SEMIHOSTING) */
  140. #else
  141. #define DEBUGINIT()
  142. #define DEBUGOUT(...)
  143. #define DEBUGSTR(str)
  144. #define DEBUGIN() (int) EOF
  145. #endif /* defined(DEBUG) */
  146. /**
  147. * @}
  148. */
  149. #ifdef __cplusplus
  150. }
  151. #endif
  152. #endif /* __BOARD_API_H_ */