matrix.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641
  1. /*
  2. Copyright 2012 Jun Wako <wakojun@gmail.com>
  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. /*
  15. * scan matrix
  16. */
  17. #include <stdint.h>
  18. #include <stdbool.h>
  19. #include <avr/io.h>
  20. #include "wait.h"
  21. #include "print.h"
  22. #include "debug.h"
  23. #include "util.h"
  24. #include "matrix.h"
  25. #include "split_util.h"
  26. #include "pro_micro.h"
  27. #include "config.h"
  28. #include "timer.h"
  29. #include "split_flags.h"
  30. #ifdef BACKLIGHT_ENABLE
  31. # include "backlight.h"
  32. extern backlight_config_t backlight_config;
  33. #endif
  34. #if defined(USE_I2C) || defined(EH)
  35. # include "i2c.h"
  36. #else // USE_SERIAL
  37. # include "serial.h"
  38. #endif
  39. #ifndef DEBOUNCING_DELAY
  40. # define DEBOUNCING_DELAY 5
  41. #endif
  42. #if (DEBOUNCING_DELAY > 0)
  43. static uint16_t debouncing_time;
  44. static bool debouncing = false;
  45. #endif
  46. #if defined(USE_I2C) || defined(EH)
  47. #if (MATRIX_COLS <= 8)
  48. # define print_matrix_header() print("\nr/c 01234567\n")
  49. # define print_matrix_row(row) print_bin_reverse8(matrix_get_row(row))
  50. # define matrix_bitpop(i) bitpop(matrix[i])
  51. # define ROW_SHIFTER ((uint8_t)1)
  52. #else
  53. # error "Currently only supports 8 COLS"
  54. #endif
  55. #else // USE_SERIAL
  56. #if (MATRIX_COLS <= 8)
  57. # define print_matrix_header() print("\nr/c 01234567\n")
  58. # define print_matrix_row(row) print_bin_reverse8(matrix_get_row(row))
  59. # define matrix_bitpop(i) bitpop(matrix[i])
  60. # define ROW_SHIFTER ((uint8_t)1)
  61. #elif (MATRIX_COLS <= 16)
  62. # define print_matrix_header() print("\nr/c 0123456789ABCDEF\n")
  63. # define print_matrix_row(row) print_bin_reverse16(matrix_get_row(row))
  64. # define matrix_bitpop(i) bitpop16(matrix[i])
  65. # define ROW_SHIFTER ((uint16_t)1)
  66. #elif (MATRIX_COLS <= 32)
  67. # define print_matrix_header() print("\nr/c 0123456789ABCDEF0123456789ABCDEF\n")
  68. # define print_matrix_row(row) print_bin_reverse32(matrix_get_row(row))
  69. # define matrix_bitpop(i) bitpop32(matrix[i])
  70. # define ROW_SHIFTER ((uint32_t)1)
  71. #endif
  72. #endif
  73. static matrix_row_t matrix_debouncing[MATRIX_ROWS];
  74. #define ERROR_DISCONNECT_COUNT 5
  75. #define ROWS_PER_HAND (MATRIX_ROWS/2)
  76. static uint8_t error_count = 0;
  77. #if ((DIODE_DIRECTION == COL2ROW) || (DIODE_DIRECTION == ROW2COL))
  78. static uint8_t row_pins[MATRIX_ROWS] = MATRIX_ROW_PINS;
  79. static uint8_t col_pins[MATRIX_COLS] = MATRIX_COL_PINS;
  80. #elif (DIODE_DIRECTION == CUSTOM_MATRIX)
  81. static uint8_t row_col_pins[MATRIX_ROWS][MATRIX_COLS] = MATRIX_ROW_COL_PINS;
  82. #endif
  83. /* matrix state(1:on, 0:off) */
  84. static matrix_row_t matrix[MATRIX_ROWS];
  85. static matrix_row_t matrix_debouncing[MATRIX_ROWS];
  86. #if (DIODE_DIRECTION == COL2ROW)
  87. static void init_cols(void);
  88. static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row);
  89. static void unselect_rows(void);
  90. static void select_row(uint8_t row);
  91. static void unselect_row(uint8_t row);
  92. #elif (DIODE_DIRECTION == ROW2COL)
  93. static void init_rows(void);
  94. static bool read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col);
  95. static void unselect_cols(void);
  96. static void unselect_col(uint8_t col);
  97. static void select_col(uint8_t col);
  98. #elif (DIODE_DIRECTION == CUSTOM_MATRIX)
  99. static void init_cols_rows(void);
  100. static bool read_cols(matrix_row_t current_matrix[], uint8_t current_row);
  101. #endif
  102. __attribute__ ((weak))
  103. void matrix_init_kb(void) {
  104. matrix_init_user();
  105. }
  106. __attribute__ ((weak))
  107. void matrix_scan_kb(void) {
  108. matrix_scan_user();
  109. }
  110. __attribute__ ((weak))
  111. void matrix_init_user(void) {
  112. }
  113. __attribute__ ((weak))
  114. void matrix_scan_user(void) {
  115. }
  116. __attribute__ ((weak))
  117. void matrix_slave_scan_user(void) {
  118. }
  119. inline
  120. uint8_t matrix_rows(void)
  121. {
  122. return MATRIX_ROWS;
  123. }
  124. inline
  125. uint8_t matrix_cols(void)
  126. {
  127. return MATRIX_COLS;
  128. }
  129. void matrix_init(void)
  130. {
  131. #ifdef DISABLE_JTAG
  132. // JTAG disable for PORT F. write JTD bit twice within four cycles.
  133. MCUCR |= (1<<JTD);
  134. MCUCR |= (1<<JTD);
  135. #endif
  136. debug_enable = true;
  137. debug_matrix = true;
  138. debug_mouse = true;
  139. // Set pinout for right half if pinout for that half is defined
  140. if (!isLeftHand) {
  141. #ifdef MATRIX_ROW_PINS_RIGHT
  142. const uint8_t row_pins_right[MATRIX_ROWS] = MATRIX_ROW_PINS_RIGHT;
  143. for (uint8_t i = 0; i < MATRIX_ROWS; i++)
  144. row_pins[i] = row_pins_right[i];
  145. #endif
  146. #ifdef MATRIX_COL_PINS_RIGHT
  147. const uint8_t col_pins_right[MATRIX_COLS] = MATRIX_COL_PINS_RIGHT;
  148. for (uint8_t i = 0; i < MATRIX_COLS; i++)
  149. col_pins[i] = col_pins_right[i];
  150. #endif
  151. }
  152. // initialize row and col
  153. #if (DIODE_DIRECTION == COL2ROW)
  154. unselect_rows();
  155. init_cols();
  156. #elif (DIODE_DIRECTION == ROW2COL)
  157. unselect_cols();
  158. init_rows();
  159. #elif (DIODE_DIRECTION == CUSTOM_MATRIX)
  160. init_cols_rows();
  161. #endif
  162. // initialize matrix state: all keys off
  163. for (uint8_t i=0; i < MATRIX_ROWS; i++) {
  164. matrix[i] = 0;
  165. matrix_debouncing[i] = 0;
  166. }
  167. matrix_init_quantum();
  168. }
  169. uint8_t _matrix_scan(void)
  170. {
  171. int offset = isLeftHand ? 0 : (ROWS_PER_HAND);
  172. #if (DIODE_DIRECTION == COL2ROW)
  173. // Set row, read cols
  174. for (uint8_t current_row = 0; current_row < ROWS_PER_HAND; current_row++) {
  175. # if (DEBOUNCING_DELAY > 0)
  176. bool matrix_changed = read_cols_on_row(matrix_debouncing+offset, current_row);
  177. if (matrix_changed) {
  178. debouncing = true;
  179. debouncing_time = timer_read();
  180. }
  181. # else
  182. read_cols_on_row(matrix+offset, current_row);
  183. # endif
  184. }
  185. #elif (DIODE_DIRECTION == ROW2COL)
  186. // Set col, read rows
  187. for (uint8_t current_col = 0; current_col < MATRIX_COLS; current_col++) {
  188. # if (DEBOUNCING_DELAY > 0)
  189. bool matrix_changed = read_rows_on_col(matrix_debouncing+offset, current_col);
  190. if (matrix_changed) {
  191. debouncing = true;
  192. debouncing_time = timer_read();
  193. }
  194. # else
  195. read_rows_on_col(matrix+offset, current_col);
  196. # endif
  197. }
  198. #elif (DIODE_DIRECTION == CUSTOM_MATRIX)
  199. // Set row, read cols
  200. for (uint8_t current_row = 0; current_row < ROWS_PER_HAND; current_row++) {
  201. # if (DEBOUNCING_DELAY > 0)
  202. bool matrix_changed = read_cols(matrix_debouncing+offset, current_row);
  203. if (matrix_changed) {
  204. debouncing = true;
  205. debouncing_time = timer_read();
  206. }
  207. # else
  208. read_cols(matrix+offset, current_row);
  209. # endif
  210. }
  211. #endif
  212. # if (DEBOUNCING_DELAY > 0)
  213. if (debouncing && (timer_elapsed(debouncing_time) > DEBOUNCING_DELAY)) {
  214. for (uint8_t i = 0; i < ROWS_PER_HAND; i++) {
  215. matrix[i+offset] = matrix_debouncing[i+offset];
  216. }
  217. debouncing = false;
  218. }
  219. # endif
  220. return 1;
  221. }
  222. #if defined(USE_I2C) || defined(EH)
  223. // Get rows from other half over i2c
  224. int i2c_transaction(void) {
  225. int slaveOffset = (isLeftHand) ? (ROWS_PER_HAND) : 0;
  226. int err = 0;
  227. // write backlight info
  228. #ifdef BACKLIGHT_ENABLE
  229. if (BACKLIT_DIRTY) {
  230. err = i2c_master_start(SLAVE_I2C_ADDRESS + I2C_WRITE);
  231. if (err) goto i2c_error;
  232. // Backlight location
  233. err = i2c_master_write(I2C_BACKLIT_START);
  234. if (err) goto i2c_error;
  235. // Write backlight
  236. i2c_master_write(get_backlight_level());
  237. BACKLIT_DIRTY = false;
  238. }
  239. #endif
  240. err = i2c_master_start(SLAVE_I2C_ADDRESS + I2C_WRITE);
  241. if (err) goto i2c_error;
  242. // start of matrix stored at I2C_KEYMAP_START
  243. err = i2c_master_write(I2C_KEYMAP_START);
  244. if (err) goto i2c_error;
  245. // Start read
  246. err = i2c_master_start(SLAVE_I2C_ADDRESS + I2C_READ);
  247. if (err) goto i2c_error;
  248. if (!err) {
  249. int i;
  250. for (i = 0; i < ROWS_PER_HAND-1; ++i) {
  251. matrix[slaveOffset+i] = i2c_master_read(I2C_ACK);
  252. }
  253. matrix[slaveOffset+i] = i2c_master_read(I2C_NACK);
  254. i2c_master_stop();
  255. } else {
  256. i2c_error: // the cable is disconnceted, or something else went wrong
  257. i2c_reset_state();
  258. return err;
  259. }
  260. #ifdef RGBLIGHT_ENABLE
  261. if (RGB_DIRTY) {
  262. err = i2c_master_start(SLAVE_I2C_ADDRESS + I2C_WRITE);
  263. if (err) goto i2c_error;
  264. // RGB Location
  265. err = i2c_master_write(I2C_RGB_START);
  266. if (err) goto i2c_error;
  267. uint32_t dword = eeconfig_read_rgblight();
  268. // Write RGB
  269. err = i2c_master_write_data(&dword, 4);
  270. if (err) goto i2c_error;
  271. RGB_DIRTY = false;
  272. i2c_master_stop();
  273. }
  274. #endif
  275. return 0;
  276. }
  277. #else // USE_SERIAL
  278. typedef struct _Serial_s2m_buffer_t {
  279. // TODO: if MATRIX_COLS > 8 change to uint8_t packed_matrix[] for pack/unpack
  280. matrix_row_t smatrix[ROWS_PER_HAND];
  281. } Serial_s2m_buffer_t;
  282. volatile Serial_s2m_buffer_t serial_s2m_buffer = {};
  283. volatile Serial_m2s_buffer_t serial_m2s_buffer = {};
  284. uint8_t volatile status0 = 0;
  285. SSTD_t transactions[] = {
  286. { (uint8_t *)&status0,
  287. sizeof(serial_m2s_buffer), (uint8_t *)&serial_m2s_buffer,
  288. sizeof(serial_s2m_buffer), (uint8_t *)&serial_s2m_buffer
  289. }
  290. };
  291. void serial_master_init(void)
  292. { soft_serial_initiator_init(transactions, TID_LIMIT(transactions)); }
  293. void serial_slave_init(void)
  294. { soft_serial_target_init(transactions, TID_LIMIT(transactions)); }
  295. int serial_transaction(void) {
  296. int slaveOffset = (isLeftHand) ? (ROWS_PER_HAND) : 0;
  297. if (soft_serial_transaction()) {
  298. return 1;
  299. }
  300. // TODO: if MATRIX_COLS > 8 change to unpack()
  301. for (int i = 0; i < ROWS_PER_HAND; ++i) {
  302. matrix[slaveOffset+i] = serial_s2m_buffer.smatrix[i];
  303. }
  304. #ifdef RGBLIGHT_ENABLE
  305. // Code to send RGB over serial goes here (not implemented yet)
  306. #endif
  307. #ifdef BACKLIGHT_ENABLE
  308. // Write backlight level for slave to read
  309. serial_m2s_buffer.backlight_level = backlight_config.enable ? backlight_config.level : 0;
  310. #endif
  311. return 0;
  312. }
  313. #endif
  314. uint8_t matrix_scan(void)
  315. {
  316. uint8_t ret = _matrix_scan();
  317. #if defined(USE_I2C) || defined(EH)
  318. if( i2c_transaction() ) {
  319. #else // USE_SERIAL
  320. if( serial_transaction() ) {
  321. #endif
  322. error_count++;
  323. if (error_count > ERROR_DISCONNECT_COUNT) {
  324. // reset other half if disconnected
  325. int slaveOffset = (isLeftHand) ? (ROWS_PER_HAND) : 0;
  326. for (int i = 0; i < ROWS_PER_HAND; ++i) {
  327. matrix[slaveOffset+i] = 0;
  328. }
  329. }
  330. } else {
  331. error_count = 0;
  332. }
  333. matrix_scan_quantum();
  334. return ret;
  335. }
  336. void matrix_slave_scan(void) {
  337. _matrix_scan();
  338. int offset = (isLeftHand) ? 0 : ROWS_PER_HAND;
  339. #if defined(USE_I2C) || defined(EH)
  340. for (int i = 0; i < ROWS_PER_HAND; ++i) {
  341. i2c_slave_buffer[I2C_KEYMAP_START+i] = matrix[offset+i];
  342. }
  343. #else // USE_SERIAL
  344. // TODO: if MATRIX_COLS > 8 change to pack()
  345. for (int i = 0; i < ROWS_PER_HAND; ++i) {
  346. serial_s2m_buffer.smatrix[i] = matrix[offset+i];
  347. }
  348. #endif
  349. matrix_slave_scan_user();
  350. }
  351. bool matrix_is_modified(void)
  352. {
  353. if (debouncing) return false;
  354. return true;
  355. }
  356. inline
  357. bool matrix_is_on(uint8_t row, uint8_t col)
  358. {
  359. return (matrix[row] & ((matrix_row_t)1<<col));
  360. }
  361. inline
  362. matrix_row_t matrix_get_row(uint8_t row)
  363. {
  364. return matrix[row];
  365. }
  366. void matrix_print(void)
  367. {
  368. print("\nr/c 0123456789ABCDEF\n");
  369. for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
  370. phex(row); print(": ");
  371. pbin_reverse16(matrix_get_row(row));
  372. print("\n");
  373. }
  374. }
  375. uint8_t matrix_key_count(void)
  376. {
  377. uint8_t count = 0;
  378. for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
  379. count += bitpop16(matrix[i]);
  380. }
  381. return count;
  382. }
  383. #if (DIODE_DIRECTION == COL2ROW)
  384. static void init_cols(void)
  385. {
  386. for(uint8_t x = 0; x < MATRIX_COLS; x++) {
  387. uint8_t pin = col_pins[x];
  388. _SFR_IO8((pin >> 4) + 1) &= ~_BV(pin & 0xF); // IN
  389. _SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF); // HI
  390. }
  391. }
  392. static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row)
  393. {
  394. // Store last value of row prior to reading
  395. matrix_row_t last_row_value = current_matrix[current_row];
  396. // Clear data in matrix row
  397. current_matrix[current_row] = 0;
  398. // Select row and wait for row selecton to stabilize
  399. select_row(current_row);
  400. wait_us(30);
  401. // For each col...
  402. for(uint8_t col_index = 0; col_index < MATRIX_COLS; col_index++) {
  403. // Select the col pin to read (active low)
  404. uint8_t pin = col_pins[col_index];
  405. uint8_t pin_state = (_SFR_IO8(pin >> 4) & _BV(pin & 0xF));
  406. // Populate the matrix row with the state of the col pin
  407. current_matrix[current_row] |= pin_state ? 0 : (ROW_SHIFTER << col_index);
  408. }
  409. // Unselect row
  410. unselect_row(current_row);
  411. return (last_row_value != current_matrix[current_row]);
  412. }
  413. static void select_row(uint8_t row)
  414. {
  415. uint8_t pin = row_pins[row];
  416. _SFR_IO8((pin >> 4) + 1) |= _BV(pin & 0xF); // OUT
  417. _SFR_IO8((pin >> 4) + 2) &= ~_BV(pin & 0xF); // LOW
  418. }
  419. static void unselect_row(uint8_t row)
  420. {
  421. uint8_t pin = row_pins[row];
  422. _SFR_IO8((pin >> 4) + 1) &= ~_BV(pin & 0xF); // IN
  423. _SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF); // HI
  424. }
  425. static void unselect_rows(void)
  426. {
  427. for(uint8_t x = 0; x < ROWS_PER_HAND; x++) {
  428. uint8_t pin = row_pins[x];
  429. _SFR_IO8((pin >> 4) + 1) &= ~_BV(pin & 0xF); // IN
  430. _SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF); // HI
  431. }
  432. }
  433. #elif (DIODE_DIRECTION == ROW2COL)
  434. static void init_rows(void)
  435. {
  436. for(uint8_t x = 0; x < ROWS_PER_HAND; x++) {
  437. uint8_t pin = row_pins[x];
  438. _SFR_IO8((pin >> 4) + 1) &= ~_BV(pin & 0xF); // IN
  439. _SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF); // HI
  440. }
  441. }
  442. static bool read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col)
  443. {
  444. bool matrix_changed = false;
  445. // Select col and wait for col selecton to stabilize
  446. select_col(current_col);
  447. wait_us(30);
  448. // For each row...
  449. for(uint8_t row_index = 0; row_index < ROWS_PER_HAND; row_index++)
  450. {
  451. // Store last value of row prior to reading
  452. matrix_row_t last_row_value = current_matrix[row_index];
  453. // Check row pin state
  454. if ((_SFR_IO8(row_pins[row_index] >> 4) & _BV(row_pins[row_index] & 0xF)) == 0)
  455. {
  456. // Pin LO, set col bit
  457. current_matrix[row_index] |= (ROW_SHIFTER << current_col);
  458. }
  459. else
  460. {
  461. // Pin HI, clear col bit
  462. current_matrix[row_index] &= ~(ROW_SHIFTER << current_col);
  463. }
  464. // Determine if the matrix changed state
  465. if ((last_row_value != current_matrix[row_index]) && !(matrix_changed))
  466. {
  467. matrix_changed = true;
  468. }
  469. }
  470. // Unselect col
  471. unselect_col(current_col);
  472. return matrix_changed;
  473. }
  474. static void select_col(uint8_t col)
  475. {
  476. uint8_t pin = col_pins[col];
  477. _SFR_IO8((pin >> 4) + 1) |= _BV(pin & 0xF); // OUT
  478. _SFR_IO8((pin >> 4) + 2) &= ~_BV(pin & 0xF); // LOW
  479. }
  480. static void unselect_col(uint8_t col)
  481. {
  482. uint8_t pin = col_pins[col];
  483. _SFR_IO8((pin >> 4) + 1) &= ~_BV(pin & 0xF); // IN
  484. _SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF); // HI
  485. }
  486. static void unselect_cols(void)
  487. {
  488. for(uint8_t x = 0; x < MATRIX_COLS; x++) {
  489. uint8_t pin = col_pins[x];
  490. _SFR_IO8((pin >> 4) + 1) &= ~_BV(pin & 0xF); // IN
  491. _SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF); // HI
  492. }
  493. }
  494. #elif (DIODE_DIRECTION == CUSTOM_MATRIX)
  495. static void init_cols_rows(void)
  496. {
  497. for(int row = 0; row < MATRIX_ROWS; row++) {
  498. for(int col = 0; col < MATRIX_COLS; col++) {
  499. uint8_t pin = row_col_pins[row][col];
  500. if(pin == NO_PIN) {
  501. continue;
  502. }
  503. // DDxn set 0 for input
  504. _SFR_IO8((pin >> 4) + 1) &= ~_BV(pin & 0xF);
  505. // PORTxn set 1 for input/pullup
  506. _SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF);
  507. }
  508. }
  509. }
  510. static bool read_cols(matrix_row_t current_matrix[], uint8_t current_row)
  511. {
  512. matrix_row_t last_row_value = current_matrix[current_row];
  513. current_matrix[current_row] = 0;
  514. for(uint8_t col_index = 0; col_index < MATRIX_COLS; col_index++) {
  515. uint8_t pin = row_col_pins[current_row][col_index];
  516. if(pin == NO_PIN) {
  517. current_matrix[current_row] |= 0;
  518. }
  519. else {
  520. uint8_t pin_state = (_SFR_IO8(pin >> 4) & _BV(pin & 0xF));
  521. current_matrix[current_row] |= pin_state ? 0 : (ROW_SHIFTER << col_index);
  522. }
  523. }
  524. return (last_row_value != current_matrix[current_row]);
  525. }
  526. #endif