blob: b9b37a4d2d1077fdbb9af18a1f7b06f5a7c3e170 [file] [log] [blame]
Austin Schuh41baf202022-01-01 14:33:40 -08001/*
2 * The MIT License (MIT)
3 *
4 * Copyright (c) 2019 Ha Thach (tinyusb.org)
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 *
24 */
25
26/* This example current worked and tested with following controller
27 * - Sony DualShock 4 [CUH-ZCT2x] VID = 0x054c, PID = 0x09cc
28 */
29
30
31#include <stdlib.h>
32#include <stdio.h>
33#include <string.h>
34
35#include "bsp/board.h"
36#include "tusb.h"
37
38//--------------------------------------------------------------------+
39// MACRO CONSTANT TYPEDEF PROTYPES
40//--------------------------------------------------------------------+
41void led_blinking_task(void);
42
43extern void cdc_task(void);
44extern void hid_app_task(void);
45
46/*------------- MAIN -------------*/
47int main(void)
48{
49 board_init();
50
51 printf("TinyUSB Host HID Controller Example\r\n");
52 printf("Note: Events only displayed for explictly supported controllers\r\n");
53
54 tusb_init();
55
56 while (1)
57 {
58 // tinyusb host task
59 tuh_task();
60 led_blinking_task();
61
62#if CFG_TUH_CDC
63 cdc_task();
64#endif
65
66#if CFG_TUH_HID
67 hid_app_task();
68#endif
69 }
70
71 return 0;
72}
73
74//--------------------------------------------------------------------+
75// TinyUSB Callbacks
76//--------------------------------------------------------------------+
77
78//--------------------------------------------------------------------+
79// Blinking Task
80//--------------------------------------------------------------------+
81void led_blinking_task(void)
82{
83 const uint32_t interval_ms = 1000;
84 static uint32_t start_ms = 0;
85
86 static bool led_state = false;
87
88 // Blink every interval ms
89 if ( board_millis() - start_ms < interval_ms) return; // not enough time
90 start_ms += interval_ms;
91
92 board_led_write(led_state);
93 led_state = 1 - led_state; // toggle
94}