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.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. #if defined(GH60_REV_CNY)
  17. /* LED Column pin configuration
  18. * pin: F0 F1 E6 C7 C6 B7 D4 B0 B1 B5 B4 D7 D6 B3 (Rev.CNY)
  19. */
  20. void led_matrix_write_cols(led_matrix_row_t cols)
  21. {
  22. (cols & (1<<0)) ? (PORTF |= (1<<PF0)) : (PORTF &= ~(1<<PF0));
  23. (cols & (1<<1)) ? (PORTF |= (1<<PF1)) : (PORTF &= ~(1<<PF1));
  24. (cols & (1<<2)) ? (PORTE |= (1<<PE6)) : (PORTE &= ~(1<<PE6));
  25. (cols & (1<<3)) ? (PORTC |= (1<<PC7)) : (PORTC &= ~(1<<PC7));
  26. (cols & (1<<4)) ? (PORTC |= (1<<PC6)) : (PORTC &= ~(1<<PC6));
  27. (cols & (1<<5)) ? (PORTB |= (1<<PB7)) : (PORTB &= ~(1<<PB7));
  28. (cols & (1<<6)) ? (PORTD |= (1<<PD4)) : (PORTD &= ~(1<<PD4));
  29. (cols & (1<<7)) ? (PORTB |= (1<<PB0)) : (PORTB &= ~(1<<PB0));
  30. (cols & (1<<8)) ? (PORTB |= (1<<PB1)) : (PORTB &= ~(1<<PB1));
  31. (cols & (1<<9)) ? (PORTB |= (1<<PB5)) : (PORTB &= ~(1<<PB5));
  32. (cols & (1<<10)) ? (PORTB |= (1<<PB4)) : (PORTB &= ~(1<<PB4));
  33. (cols & (1<<11)) ? (PORTD |= (1<<PD7)) : (PORTD &= ~(1<<PD7));
  34. (cols & (1<<12)) ? (PORTD |= (1<<PD6)) : (PORTD &= ~(1<<PD6));
  35. (cols & (1<<13)) ? (PORTB |= (1<<PB3)) : (PORTB &= ~(1<<PB3));
  36. }
  37. /* LED Row pin configuration
  38. * row: 0 1 2 3 4 5
  39. * pin: B6 F5 F6 F7 F4 B2
  40. */
  41. void led_matrix_unselect_rows(void)
  42. {
  43. // unselect key matrix rows
  44. //DDRD &= ~0b00101111;
  45. //PORTD &= ~0b00101111;
  46. // bit 76543210
  47. DDRB &= ~0b01000100;
  48. PORTB &= ~0b01000100;
  49. // bit 76543210
  50. DDRF &= ~0b11110000;
  51. PORTF &= ~0b11110000;
  52. }
  53. /* LED Row pin configuration
  54. * row: 0 1 2 3 4 5
  55. * pin: B6 F5 F6 F7 F4 B2
  56. */
  57. void led_matrix_select_row(uint8_t row)
  58. {
  59. switch (row) {
  60. case 0:
  61. DDRB |= (1<<PB6);
  62. PORTB |= (1<<PB6);
  63. break;
  64. case 1:
  65. DDRF |= (1<<PF5);
  66. PORTF |= (1<<PF5);
  67. break;
  68. case 2:
  69. DDRF |= (1<<PF6);
  70. PORTF |= (1<<PF6);
  71. break;
  72. case 3:
  73. DDRF |= (1<<PF7);
  74. PORTF |= (1<<PF7);
  75. break;
  76. case 4:
  77. DDRF |= (1<<PF4);
  78. PORTF |= (1<<PF4);
  79. break;
  80. case 5:
  81. DDRB |= (1<<PB2);
  82. PORTB |= (1<<PB2);
  83. break;
  84. }
  85. }
  86. #endif