summaryrefslogtreecommitdiff
path: root/demos/device/keyboard/main.c
blob: 19f2da104d9555b09892ed0710c6938a6929ffa8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#include <cr_section_macros.h>
#include <NXP/crp.h>
#include "boards/board.h"
#include "tusb.h"

// Variable to store CRP value in. Will be placed automatically
// by the linker when "Enable Code Read Protect" selected.
// See crp.h header for more information
__CRP const unsigned int CRP_WORD = CRP_NO_CRP ;

int main(void) 
{
  uint32_t current_tick = system_ticks;

  board_init();
  tusb_init();

  while (1)
  {
    if (current_tick + 1000 < system_ticks)
    {
      current_tick += 1000;
      board_leds(0x01, (current_tick/1000)%2); /* Toggle LED once per second */

      printf("tinyusb: " __DATE__ "\t" __TIME__ "\n");

      #if !(defined TUSB_CFG_DEVICE_CDC) && 0
      if (usb_isConfigured())
      {
        #ifdef TUSB_CFG_DEVICE_HID_KEYBOARD
          uint8_t keys[6] = {HID_USAGE_KEYBOARD_aA};
          tusb_hid_keyboard_sendKeys(0x00, keys, 1);
        #endif

        #ifdef TUSB_CFG_DEVICE_HID_MOUSE          
          tusb_hid_mouse_send(0, 10, 10);
        #endif
      }
      #endif
    }

    #if defined TUSB_CFG_DEVICE_CDC && 0
    if (usb_isConfigured())
    {
      uint8_t cdc_char;
      if( tusb_cdc_getc(&cdc_char) )
      {
        switch (cdc_char)
        {
          #ifdef TUSB_CFG_DEVICE_HID_KEYBOARD
          case '1' :
          {
            uint8_t keys[6] = {HID_USAGE_KEYBOARD_aA + 'e' - 'a'};
            tusb_hid_keyboard_sendKeys(0x08, keys, 1); // windows + E --> open explorer
          }
          break;
          #endif

          #ifdef TUSB_CFG_DEVICE_HID_MOUSE
          case '2' :
            tusb_hid_mouse_send(0, 10, 10);
          break;
          #endif

          default :
            cdc_char = toupper(cdc_char);
            tusb_cdc_putc(cdc_char);
          break;

        }
      }
    }
#endif
  }

  return 0;
}