aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Code_Composer/twine_usblib_demo/main.c
blob: d7bcae1dd3329d6aa7612b0f33fcf5d87f480d28 (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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#include <stdbool.h>
#include <stdlib.h>
#include <stdint.h>
#include "inc/hw_ints.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "inc/hw_uart.h"
#include "driverlib/debug.h"
#include "driverlib/gpio.h"
#include "driverlib/interrupt.h"
#include "driverlib/sysctl.h"
#include "driverlib/systick.h"
#include "driverlib/timer.h"
#include "driverlib/uart.h"
#include "driverlib/usb.h"
#include "driverlib/rom.h"
#include "driverlib/rom_map.h"
#include "drivers/pinout.h"
#include "usblib/usblib.h"
#include "usblib/usbcdc.h"
#include "usblib/usb-ids.h"
#include "usblib/device/usbdevice.h"
#include "usblib/device/usbdcdc.h"
#include "utils/ustdlib.h"
#include "usb_serial_adapter.h"
#include "graphics_adapter.h"
#include "protobuf/person-pb-c.h"

//*****************************************************************************
//
// The system tick rate expressed both as ticks per second and a millisecond
// period.
//
//*****************************************************************************
#define TICKS_PER_SECOND        100

//*****************************************************************************
//
// Global system tick counter
//
//*****************************************************************************
static volatile uint32_t g_ui32SysTickCount = 0;

// Flags used to pass commands from interrupt context to the main loop.
static volatile uint32_t g_ui32Flags;


//*****************************************************************************
//
// Interrupt handler for the system tick counter.
//
//*****************************************************************************
void SysTickHandler(void)
{
    // Update our system time.
    g_ui32SysTickCount++;
}

//*****************************************************************************
//
// Interrupt handler for the UART which we are redirecting via USB.
//
//*****************************************************************************
void USB0Handler(void)
{
    InitUSB();
}

void receive_callback(char* buffer, size_t length)
{
    //SendChars(buffer,length);
     draw_string(buffer, length);
     //draw_image((uint8_t *)buffer);

//    Person* p = person__unpack (NULL, length, (uint8_t*)buffer);
//    void* buf = malloc (length);
//    person__pack (p, buf);
//    SendChars(buf,length);
//    free(p);
//    free(buf);
}

int main(void)
{
    uint32_t  ui32SysClock, ui32PLLRate;

    // Set the system clock to run at 120MHz from the PLL.
    ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
                                           SYSCTL_OSC_MAIN | SYSCTL_USE_PLL |
                                           SYSCTL_CFG_VCO_480), 120000000);

    // Configure the device pins.
    PinoutSet();

    // Save the PLL rate used by this application.
    SysCtlVCOGet(SYSCTL_XTAL_25MHZ, &ui32PLLRate);

    // Enable the system tick.
    ROM_SysTickPeriodSet(ui32SysClock / TICKS_PER_SECOND);
    ROM_SysTickIntEnable();
    ROM_SysTickEnable();

    init_graphics(ui32SysClock);

    RegisterReceiveCallback(&receive_callback);
    StartUSB(ui32SysClock);

	while(1){};
}