examples/tests/spi/spi_controller_transfer/main.c
static void button_cb(__attribute__((unused)) int btn_num,
                      __attribute__ ((unused)) int val,
                      __attribute__ ((unused)) int arg2,
                      __attribute__ ((unused)) void* userdata) {
  if (val == 1) {
    if (toggle) {
      // This is the first read write; note that this is
      // inverted from the spi_slave_transfer, as we do
      // not call spi_read_write until after the button
      // is pressed.
      spi_read_write(wbuf, rbuf, BUF_SIZE, write_cb, NULL);
    } else {
      spi_read_write(rbuf, wbuf, BUF_SIZE, write_cb, NULL);
    }
    // Note that the toggle is reset inside the button callback,
    // not the write completed callback. This decision was arbitrary.
    toggle = !toggle;
  }
  printf("Button pushed.\n");
}
// This is the callback for the button press.
// Each button press represents a transfer, and
// we do not start transfering until the button
// has been pressed.
This is the callback for the button press.
Each button press represents a transfer, and
we do not start transfering until the button
has been pressed.
This is the callback for the button press . Each button press represents a transfer and we do not start transfering until the button has been pressed .
static void button_cb(__attribute__((unused)) int btn_num,
                      __attribute__ ((unused)) int val,
                      __attribute__ ((unused)) int arg2,
                      __attribute__ ((unused)) void* userdata) {
  if (val == 1) {
    if (toggle) {
      spi_read_write(wbuf, rbuf, BUF_SIZE, write_cb, NULL);
    } else {
      spi_read_write(rbuf, wbuf, BUF_SIZE, write_cb, NULL);
    }
    toggle = !toggle;
  }
  printf("Button pushed.\n");
}
static void button_cb ( __attribute__ ( ( unused ) ) int btn_num , __attribute__ ( ( unused ) ) int val , __attribute__ ( ( unused ) ) int arg2 , __attribute__ ( ( unused ) ) void * userdata ) { if ( val == 1 ) { if ( toggle ) { spi_read_write ( wbuf , rbuf , BUF_SIZE , write_cb , NULL ) ; } else { spi_read_write ( rbuf , wbuf , BUF_SIZE , write_cb , NULL ) ; } toggle = ! toggle ; } printf ( " \n " ) ; }
This is the callback for the button press.
This is the callback for the button press .
// This is the first read write; note that this is // inverted from the spi_slave_transfer, as we do // not call spi_read_write until after the button // is pressed. // Note that the toggle is reset inside the button callback, // not the write completed callback. This decision was arbitrary.