main.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. /****************************************************************************
  2. * Copyright 2021 Gorgon Meducer (Email:embedded_zhuoran@hotmail.com) *
  3. * *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); *
  5. * you may not use this file except in compliance with the License. *
  6. * You may obtain a copy of the License at *
  7. * *
  8. * http://www.apache.org/licenses/LICENSE-2.0 *
  9. * *
  10. * Unless required by applicable law or agreed to in writing, software *
  11. * distributed under the License is distributed on an "AS IS" BASIS, *
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
  13. * See the License for the specific language governing permissions and *
  14. * limitations under the License. *
  15. * *
  16. ****************************************************************************/
  17. /*============================ INCLUDES ======================================*/
  18. #include "pico/stdlib.h"
  19. #include "perf_counter.h"
  20. #if defined(__PICO_USE_LCD_1IN3__) && __PICO_USE_LCD_1IN3__
  21. #include "DEV_Config.h"
  22. #include "LCD_1In3.h"
  23. #include "GLCD_Config.h"
  24. #endif
  25. #include <stdio.h>
  26. #include "RTE_Components.h"
  27. #if defined(RTE_Compiler_EventRecorder) && defined(RTE_Compiler_IO_STDOUT_EVR)
  28. # include <EventRecorder.h>
  29. #endif
  30. #if defined(RTE_Script_PikaScript) || defined(USING_PIKAPYTHON)
  31. # include "pikaScript.h"
  32. #endif
  33. #if defined(__RTE_ACCELERATION_ARM_2D__) || defined(RTE_Acceleration_Arm_2D)
  34. # include "arm_2d.h"
  35. # include "arm_2d_helper.h"
  36. # include "arm_2d_disp_adapters.h"
  37. # include "arm_2d_scenes.h"
  38. #endif
  39. #if defined(__RTE_ACCELERATION_ARM_2D_EXTRA_BENCHMARK_WATCH_PANEL__) \
  40. || defined(__RTE_ACCELERATION_ARM_2D_EXTRA_BENCHMARK_GENERIC__)
  41. # include "arm_2d_benchmark.h"
  42. #endif
  43. /*============================ MACROS ========================================*/
  44. #define TOP (0x1FFF)
  45. /*============================ MACROFIED FUNCTIONS ===========================*/
  46. #ifndef ABS
  47. # define ABS(__N) ((__N) < 0 ? -(__N) : (__N))
  48. #endif
  49. #ifndef _BV
  50. # define _BV(__N) ((uint32_t)1<<(__N))
  51. #endif
  52. /*============================ TYPES =========================================*/
  53. /*============================ GLOBAL VARIABLES ==============================*/
  54. /*============================ LOCAL VARIABLES ===============================*/
  55. /*============================ PROTOTYPES ====================================*/
  56. /*============================ IMPLEMENTATION ================================*/
  57. void SysTick_Handler(void)
  58. {
  59. }
  60. /*! \brief set the 16-level led gradation
  61. *! \param hwLevel gradation
  62. *! \return none
  63. */
  64. static void set_led_gradation(uint16_t hwLevel)
  65. {
  66. static uint16_t s_hwCounter = 0;
  67. if (hwLevel >= s_hwCounter) {
  68. gpio_put(PICO_DEFAULT_LED_PIN, 1);
  69. } else {
  70. gpio_put(PICO_DEFAULT_LED_PIN, 0);
  71. }
  72. s_hwCounter++;
  73. s_hwCounter &= TOP;
  74. }
  75. static void breath_led(void)
  76. {
  77. static uint16_t s_hwCounter = 0;
  78. static int16_t s_nGray = (TOP >> 1);
  79. s_hwCounter++;
  80. if (!(s_hwCounter & (_BV(10)-1))) {
  81. s_nGray++;
  82. if (s_nGray == TOP) {
  83. s_nGray = 0;
  84. }
  85. }
  86. set_led_gradation(ABS(s_nGray - (TOP >> 1)));
  87. }
  88. static void system_init(void)
  89. {
  90. extern void SystemCoreClockUpdate();
  91. SystemCoreClockUpdate();
  92. /*! \note if you do want to use SysTick in your application, please use
  93. *! init_cycle_counter(true);
  94. *! instead of
  95. *! init_cycle_counter(false);
  96. */
  97. init_cycle_counter(false);
  98. #if defined(RTE_Compiler_EventRecorder) && defined(RTE_Compiler_IO_STDOUT_EVR)
  99. EventRecorderInitialize(0, 1);
  100. #endif
  101. stdio_init_all();
  102. gpio_init(PICO_DEFAULT_LED_PIN);
  103. gpio_set_dir(PICO_DEFAULT_LED_PIN, GPIO_OUT);
  104. #if defined(__PICO_USE_LCD_1IN3__) && __PICO_USE_LCD_1IN3__
  105. DEV_Delay_ms(100);
  106. if(DEV_Module_Init()!=0){
  107. //assert(0);
  108. }
  109. DEV_SET_PWM(50);
  110. /* LCD Init */
  111. LCD_1IN3_Init(HORIZONTAL);
  112. LCD_1IN3_Clear(GLCD_COLOR_BLUE);
  113. for (int n = 0; n < KEY_NUM; n++) {
  114. dev_key_init(n);
  115. }
  116. #endif
  117. }
  118. int stdin_getchar(void);
  119. char pika_platform_getchar(void) {
  120. return stdin_getchar();
  121. }
  122. int main(void)
  123. {
  124. system_init();
  125. __cycleof__("printf") {
  126. printf("Hello Pico-Template\r\n");
  127. }
  128. #if defined(RTE_Script_PikaScript) || defined(USING_PIKAPYTHON)
  129. pikaScriptInit();
  130. #endif
  131. #if defined( __PERF_COUNTER_COREMARK__ ) && __PERF_COUNTER_COREMARK__
  132. printf("\r\nRun Coremark 1.0...\r\n");
  133. coremark_main();
  134. #endif
  135. #if defined(__RTE_ACCELERATION_ARM_2D_EXTRA_BENCHMARK_WATCH_PANEL__) \
  136. || defined(__RTE_ACCELERATION_ARM_2D_EXTRA_BENCHMARK_GENERIC__)
  137. arm_2d_run_benchmark();
  138. #endif
  139. #if defined(__RTE_ACCELERATION_ARM_2D__) || defined(RTE_Acceleration_Arm_2D)
  140. arm_2d_init();
  141. disp_adapter0_init();
  142. //arm_2d_scene_player_switch_to_next_scene(&DISP0_ADAPTER);
  143. #endif
  144. while (true) {
  145. breath_led();
  146. #if defined(__RTE_ACCELERATION_ARM_2D__) || defined(RTE_Acceleration_Arm_2D)
  147. disp_adapter0_task();
  148. #endif
  149. //gpio_put(PICO_DEFAULT_LED_PIN, 1);
  150. //sleep_ms(500);
  151. //gpio_put(PICO_DEFAULT_LED_PIN, 0);
  152. //sleep_ms(500);
  153. }
  154. //return 0;
  155. }