1. #include "gd32f3x0.h" 2. #include "led75.h" 3. #include "gd32f3x0_gpio.h" 5. uint8_t frame[WIDTH * HEIGHT]; 6. void sda_r(unsigned int value) 7. { 8. gpio_bit_write(GPIOB, GPIO_PIN_13, (bit_status)value); 9. } 10. void sda_g(unsigned int value) 11. { 12. gpio_bit_write(GPIOB, GPIO_PIN_14, (bit_status)value); 13. } 14. void sda_b(unsigned int value) 15. { 16. gpio_bit_write(GPIOB, GPIO_PIN_15, (bit_status)value); 17. } 18. void sda_rg(unsigned int value) 19. { 20. gpio_bit_write(GPIOB, GPIO_PIN_13, (bit_status)value); 21. gpio_bit_write(GPIOB, GPIO_PIN_14, (bit_status)value); 22. } 23. void sda_gb(unsigned int value) 24. { 25. gpio_bit_write(GPIOB, GPIO_PIN_14, (bit_status)value); 26. gpio_bit_write(GPIOB, GPIO_PIN_15, (bit_status)value); 27. } 28. void sda_rb(unsigned int value) 29. { 30. gpio_bit_write(GPIOB, GPIO_PIN_13, (bit_status)value); 31. gpio_bit_write(GPIOB, GPIO_PIN_15, (bit_status)value); 32. } 33. void sda_rgb(unsigned int value) 34. { 35. gpio_bit_write(GPIOB, GPIO_PIN_13, (bit_status)value); 36. gpio_bit_write(GPIOB, GPIO_PIN_14, (bit_status)value); 37. gpio_bit_write(GPIOB, GPIO_PIN_15, (bit_status)value); 38. } 39. void sda_rs(unsigned int value) 40. { 41. gpio_bit_write(GPIOB, GPIO_PIN_12, (bit_status)value); 42. } 43. void sda_gs(unsigned int value) 44. { 45. gpio_bit_write(GPIOB, GPIO_PIN_0, (bit_status)value); 46. } 47. void sda_bs(unsigned int value) 48. { 49. gpio_bit_write(GPIOB, GPIO_PIN_1, (bit_status)value); 50. } 51. void sda_rgs(unsigned int value) 52. { 53. gpio_bit_write(GPIOB, GPIO_PIN_12, (bit_status)value); 54. gpio_bit_write(GPIOB, GPIO_PIN_0, (bit_status)value); 55. } 56. void sda_gbs(unsigned int value) 57. { 58. gpio_bit_write(GPIOB, GPIO_PIN_0, (bit_status)value); 59. gpio_bit_write(GPIOB, GPIO_PIN_1, (bit_status)value); 60. } 61. void sda_rbs(unsigned int value) 62. { 63. gpio_bit_write(GPIOB, GPIO_PIN_12, (bit_status)value); 64. gpio_bit_write(GPIOB, GPIO_PIN_1, (bit_status)value); 65. } 66. void sda_rgbs(unsigned int value) 67. { 68. gpio_bit_write(GPIOB, GPIO_PIN_12, (bit_status)value); 69. gpio_bit_write(GPIOB, GPIO_PIN_0, (bit_status)value); 70. gpio_bit_write(GPIOB, GPIO_PIN_1, (bit_status)value); 71. } 72. color_select_t led1[7] = {sda_r, sda_g, sda_b, sda_rg, sda_gb, sda_rb, sda_rgb}; 73. color_select_t led2[7] = {sda_rs, sda_gs, sda_bs, sda_rgs, sda_gbs, sda_rbs, sda_rgbs}; 74. void (*led1_send_data)(unsigned int); 75. void (*led2_send_data)(unsigned int); 76. void shcp_set(void) 77. { 78. gpio_bit_set(GPIOB, GPIO_PIN_10); 79. } 80. void shcp_clear(void) 81. { 82. gpio_bit_reset(GPIOB, GPIO_PIN_10); 83. } 84. void stcp_set(void) 85. { 86. gpio_bit_set(GPIOB, GPIO_PIN_2); 87. } 88. void stcp_clear(void) 89. { 90. gpio_bit_reset(GPIOB, GPIO_PIN_2); 91. } 92. void oe_set(void) 93. { 94. gpio_bit_set(GPIOB, GPIO_PIN_11); 95. } 96. void oe_clear(void) 97. { 98. gpio_bit_reset(GPIOB, GPIO_PIN_11); 99. } 100. void led75_abc_control(unsigned int abc, unsigned int on_off) 101. { 102. switch(abc) 103. { 104. case LED75_A: 105. gpio_bit_write(LED75_A_PORT, LED75_A_PIN, (bit_status)on_off); 106. break; 107. case LED75_B: 108. gpio_bit_write(LED75_B_PORT, LED75_B_PIN, (bit_status)on_off); 109. break; 110. case LED75_C: 111. gpio_bit_write(LED75_C_PORT, LED75_C_PIN, (bit_status)on_off); 112. break; 113. default: 114. //assert(0); 115. break; 116. } 117. } 118. void line_scan(unsigned int line) 119. { 120. switch(line) 121. { 122. case 0: 123. led75_abc_control(LED75_A, 0); 124. led75_abc_control(LED75_B, 0); 125. led75_abc_control(LED75_C, 0); 126. break; 127. case 1: 128. led75_abc_control(LED75_A, 1); 129. led75_abc_control(LED75_B, 0); 130. led75_abc_control(LED75_C, 0); 131. break; 132. case 2: 133. led75_abc_control(LED75_A, 0); 134. led75_abc_control(LED75_B, 1); 135. led75_abc_control(LED75_C, 0); 136. break; 137. case 3: 138. led75_abc_control(LED75_A, 1); 139. led75_abc_control(LED75_B, 1); 140. led75_abc_control(LED75_C, 0); 141. break; 142. case 4: 143. led75_abc_control(LED75_A, 0); 144. led75_abc_control(LED75_B, 0); 145. led75_abc_control(LED75_C, 1); 146. break; 147. case 5: 148. led75_abc_control(LED75_A, 1); 149. led75_abc_control(LED75_B, 0); 150. led75_abc_control(LED75_C, 1); 151. break; 152. case 6: 153. led75_abc_control(LED75_A, 0); 154. led75_abc_control(LED75_B, 1); 155. led75_abc_control(LED75_C, 1); 156. break; 157. case 7: 158. led75_abc_control(LED75_A, 1); 159. led75_abc_control(LED75_B, 1); 160. led75_abc_control(LED75_C, 1); 161. break; 162. default: 163. break; 164. } 165. } 166. void led_delay(unsigned int cnt) 167. { 168. volatile unsigned int i; 169. for(i=0; i 170. { 171. __NOP; 172. } 173. } 174. void led_matrix_display(void) 175. { 176. unsigned int i, j; 177. unsigned int color; 178. oe_set(); 179. /* 8 line per led */ 180. for(i=0; i<8; i++) 181. { 182. color = i; 183. led1_send_data = led1[color].proc; 184. led2_send_data = led2[color].proc; 185. sda_rgb(0); 186. sda_rgbs(0); 187. for(j=0; j 188. { 189. shcp_clear(); 190. (*led1_send_data)(frame[i * WIDTH + j]); 191. (*led2_send_data)(frame[(i + 8) * WIDTH + j]); 192. shcp_set(); 193. } 194. line_scan(i); 195. stcp_clear(); 196. stcp_set(); 197. oe_clear(); 198. //delay_us(100); 199. led_delay(0x2ff); 200. oe_set(); 201. } 202. }
|