You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

led_matrix.c 2.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. Copyright 2013,2014 Kai Ryu <[email protected]>
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. #include <avr/io.h>
  15. #include "led_matrix.h"
  16. #ifdef LED_MATRIX_ENABLE
  17. #if defined(GH60_REV_CNY)
  18. /* LED Column pin configuration
  19. * pin: F0 F1 E6 C7 C6 B7 D4 B0 B1 B5 B4 D7 D6 B3 (Rev.CNY)
  20. */
  21. void led_matrix_write_cols(led_matrix_row_t cols)
  22. {
  23. (cols & (1<<0)) ? (PORTF |= (1<<PF0)) : (PORTF &= ~(1<<PF0));
  24. (cols & (1<<1)) ? (PORTF |= (1<<PF1)) : (PORTF &= ~(1<<PF1));
  25. (cols & (1<<2)) ? (PORTE |= (1<<PE6)) : (PORTE &= ~(1<<PE6));
  26. (cols & (1<<3)) ? (PORTC |= (1<<PC7)) : (PORTC &= ~(1<<PC7));
  27. (cols & (1<<4)) ? (PORTC |= (1<<PC6)) : (PORTC &= ~(1<<PC6));
  28. (cols & (1<<5)) ? (PORTB |= (1<<PB7)) : (PORTB &= ~(1<<PB7));
  29. (cols & (1<<6)) ? (PORTD |= (1<<PD4)) : (PORTD &= ~(1<<PD4));
  30. (cols & (1<<7)) ? (PORTB |= (1<<PB0)) : (PORTB &= ~(1<<PB0));
  31. (cols & (1<<8)) ? (PORTB |= (1<<PB1)) : (PORTB &= ~(1<<PB1));
  32. (cols & (1<<9)) ? (PORTB |= (1<<PB5)) : (PORTB &= ~(1<<PB5));
  33. (cols & (1<<10)) ? (PORTB |= (1<<PB4)) : (PORTB &= ~(1<<PB4));
  34. (cols & (1<<11)) ? (PORTD |= (1<<PD7)) : (PORTD &= ~(1<<PD7));
  35. (cols & (1<<12)) ? (PORTD |= (1<<PD6)) : (PORTD &= ~(1<<PD6));
  36. (cols & (1<<13)) ? (PORTB |= (1<<PB3)) : (PORTB &= ~(1<<PB3));
  37. }
  38. /* LED Row pin configuration
  39. * row: 0 1 2 3 4 5
  40. * pin: B6 F5 F6 F7 F4 B2
  41. */
  42. void led_matrix_unselect_rows(void)
  43. {
  44. // bit 76543210
  45. DDRB &= ~0b01000100;
  46. PORTB &= ~0b01000100;
  47. // bit 76543210
  48. DDRF &= ~0b11110000;
  49. PORTF &= ~0b11110000;
  50. }
  51. /* LED Row pin configuration
  52. * row: 0 1 2 3 4 5
  53. * pin: B6 F5 F6 F7 F4 B2
  54. */
  55. void led_matrix_select_row(uint8_t row)
  56. {
  57. switch (row) {
  58. case 0:
  59. DDRB |= (1<<PB6);
  60. PORTB |= (1<<PB6);
  61. break;
  62. case 1:
  63. DDRF |= (1<<PF5);
  64. PORTF |= (1<<PF5);
  65. break;
  66. case 2:
  67. DDRF |= (1<<PF6);
  68. PORTF |= (1<<PF6);
  69. break;
  70. case 3:
  71. DDRF |= (1<<PF7);
  72. PORTF |= (1<<PF7);
  73. break;
  74. case 4:
  75. DDRF |= (1<<PF4);
  76. PORTF |= (1<<PF4);
  77. break;
  78. case 5:
  79. DDRB |= (1<<PB2);
  80. PORTB |= (1<<PB2);
  81. break;
  82. }
  83. }
  84. #endif
  85. #endif