main.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*
  2. ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. #include <stdio.h>
  14. #include <string.h>
  15. #include "ch.h"
  16. #include "hal.h"
  17. #include "chprintf.h"
  18. #include "st7735.h"
  19. /* Private variables */
  20. /*
  21. * SPI configuration structure.
  22. * Speed 12 MHz, CPHA=0, CPOL=0, 8bits frames, MSb transmitted first.
  23. * Soft slave select.
  24. */
  25. static const SPIConfig spi1cfg = {
  26. .circular = false,
  27. .slave = false,
  28. .data_cb = NULL,
  29. .error_cb = NULL,
  30. .cr1 = 0U,
  31. .cr2 = 0U
  32. };
  33. /*===========================================================================*/
  34. /* Generic code. */
  35. /*===========================================================================*/
  36. /*
  37. * Blinker thread, times are in milliseconds.
  38. */
  39. static THD_WORKING_AREA(waThread1, 128);
  40. static __attribute__((noreturn)) THD_FUNCTION(Thread1, arg) {
  41. (void)arg;
  42. chRegSetThreadName("blinker");
  43. while (true) {
  44. palClearLine(LINE_LED);
  45. chThdSleepMilliseconds(500);
  46. palSetLine(LINE_LED);
  47. chThdSleepMilliseconds(500);
  48. }
  49. }
  50. /*
  51. * Application entry point.
  52. */
  53. int main(void) {
  54. /*
  55. * System initializations.
  56. * - HAL initialization, this also initializes the configured device drivers
  57. * and performs the board-specific initializations.
  58. * - Kernel initialization, the main() function becomes a thread and the
  59. * RTOS is active.
  60. */
  61. halInit();
  62. chSysInit();
  63. /*
  64. * Initializes a SPI1 driver.
  65. */
  66. spiStart(&SPID1, &spi1cfg);
  67. spiSelectI(&SPID1);
  68. /*
  69. * Creates the blinker thread.
  70. */
  71. chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
  72. /*
  73. * LCD
  74. */
  75. ST7735_Init();
  76. ST7735_FillScreen(ST7735_BLACK);
  77. ST7735_WriteString(0, 0, "Font_7x10, red on black, lorem ipsum dolor sit amet", Font_7x10, ST7735_RED, ST7735_BLACK);
  78. ST7735_WriteString(0, 30, "Font_7x10, green on black, lorem ipsum dolor sit amet", Font_7x10, ST7735_GREEN, ST7735_BLACK);
  79. ST7735_WriteString(0, 60, "Font_7x10, blue on black, lorem ipsum dolor sit amet", Font_7x10, ST7735_BLUE, ST7735_BLACK);
  80. ST7735_WriteString(0, 90, "Font_7x10, yellow on black, lorem ipsum dolor sit amet", Font_7x10, ST7735_YELLOW, ST7735_BLACK);
  81. ST7735_WriteString(0, 120, "Last row?", Font_7x10, ST7735_CYAN, ST7735_BLACK);
  82. /*
  83. * Normal main() thread activity.
  84. */
  85. while (true) {
  86. chThdSleepMilliseconds(500);
  87. }
  88. }