Kévin Redon | 69b92d9 | 2019-01-24 16:39:20 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Code generated from Atmel Start. |
| 3 | * |
| 4 | * This file will be overwritten when reconfiguring your Atmel Start project. |
| 5 | * Please copy examples or other code you want to keep to a separate file |
| 6 | * to avoid losing it when reconfiguring. |
| 7 | */ |
| 8 | |
| 9 | #include "driver_init.h" |
| 10 | #include <peripheral_clk_config.h> |
| 11 | #include <utils.h> |
| 12 | #include <hal_init.h> |
| 13 | |
| 14 | void USB_DEVICE_INSTANCE_PORT_init(void) |
| 15 | { |
| 16 | |
| 17 | gpio_set_pin_direction(PA24, |
| 18 | // <y> Pin direction |
| 19 | // <id> pad_direction |
| 20 | // <GPIO_DIRECTION_OFF"> Off |
| 21 | // <GPIO_DIRECTION_IN"> In |
| 22 | // <GPIO_DIRECTION_OUT"> Out |
| 23 | GPIO_DIRECTION_OUT); |
| 24 | |
| 25 | gpio_set_pin_level(PA24, |
| 26 | // <y> Initial level |
| 27 | // <id> pad_initial_level |
| 28 | // <false"> Low |
| 29 | // <true"> High |
| 30 | false); |
| 31 | |
| 32 | gpio_set_pin_pull_mode(PA24, |
| 33 | // <y> Pull configuration |
| 34 | // <id> pad_pull_config |
| 35 | // <GPIO_PULL_OFF"> Off |
| 36 | // <GPIO_PULL_UP"> Pull-up |
| 37 | // <GPIO_PULL_DOWN"> Pull-down |
| 38 | GPIO_PULL_OFF); |
| 39 | |
| 40 | gpio_set_pin_function(PA24, |
| 41 | // <y> Pin function |
| 42 | // <id> pad_function |
| 43 | // <i> Auto : use driver pinmux if signal is imported by driver, else turn off function |
| 44 | // <PINMUX_PA24H_USB_DM"> Auto |
| 45 | // <GPIO_PIN_FUNCTION_OFF"> Off |
| 46 | // <GPIO_PIN_FUNCTION_A"> A |
| 47 | // <GPIO_PIN_FUNCTION_B"> B |
| 48 | // <GPIO_PIN_FUNCTION_C"> C |
| 49 | // <GPIO_PIN_FUNCTION_D"> D |
| 50 | // <GPIO_PIN_FUNCTION_E"> E |
| 51 | // <GPIO_PIN_FUNCTION_F"> F |
| 52 | // <GPIO_PIN_FUNCTION_G"> G |
| 53 | // <GPIO_PIN_FUNCTION_H"> H |
| 54 | // <GPIO_PIN_FUNCTION_I"> I |
| 55 | // <GPIO_PIN_FUNCTION_J"> J |
| 56 | // <GPIO_PIN_FUNCTION_K"> K |
| 57 | // <GPIO_PIN_FUNCTION_L"> L |
| 58 | // <GPIO_PIN_FUNCTION_M"> M |
| 59 | // <GPIO_PIN_FUNCTION_N"> N |
| 60 | PINMUX_PA24H_USB_DM); |
| 61 | |
| 62 | gpio_set_pin_direction(PA25, |
| 63 | // <y> Pin direction |
| 64 | // <id> pad_direction |
| 65 | // <GPIO_DIRECTION_OFF"> Off |
| 66 | // <GPIO_DIRECTION_IN"> In |
| 67 | // <GPIO_DIRECTION_OUT"> Out |
| 68 | GPIO_DIRECTION_OUT); |
| 69 | |
| 70 | gpio_set_pin_level(PA25, |
| 71 | // <y> Initial level |
| 72 | // <id> pad_initial_level |
| 73 | // <false"> Low |
| 74 | // <true"> High |
| 75 | false); |
| 76 | |
| 77 | gpio_set_pin_pull_mode(PA25, |
| 78 | // <y> Pull configuration |
| 79 | // <id> pad_pull_config |
| 80 | // <GPIO_PULL_OFF"> Off |
| 81 | // <GPIO_PULL_UP"> Pull-up |
| 82 | // <GPIO_PULL_DOWN"> Pull-down |
| 83 | GPIO_PULL_OFF); |
| 84 | |
| 85 | gpio_set_pin_function(PA25, |
| 86 | // <y> Pin function |
| 87 | // <id> pad_function |
| 88 | // <i> Auto : use driver pinmux if signal is imported by driver, else turn off function |
| 89 | // <PINMUX_PA25H_USB_DP"> Auto |
| 90 | // <GPIO_PIN_FUNCTION_OFF"> Off |
| 91 | // <GPIO_PIN_FUNCTION_A"> A |
| 92 | // <GPIO_PIN_FUNCTION_B"> B |
| 93 | // <GPIO_PIN_FUNCTION_C"> C |
| 94 | // <GPIO_PIN_FUNCTION_D"> D |
| 95 | // <GPIO_PIN_FUNCTION_E"> E |
| 96 | // <GPIO_PIN_FUNCTION_F"> F |
| 97 | // <GPIO_PIN_FUNCTION_G"> G |
| 98 | // <GPIO_PIN_FUNCTION_H"> H |
| 99 | // <GPIO_PIN_FUNCTION_I"> I |
| 100 | // <GPIO_PIN_FUNCTION_J"> J |
| 101 | // <GPIO_PIN_FUNCTION_K"> K |
| 102 | // <GPIO_PIN_FUNCTION_L"> L |
| 103 | // <GPIO_PIN_FUNCTION_M"> M |
| 104 | // <GPIO_PIN_FUNCTION_N"> N |
| 105 | PINMUX_PA25H_USB_DP); |
| 106 | } |
| 107 | |
| 108 | /* The USB module requires a GCLK_USB of 48 MHz ~ 0.25% clock |
| 109 | * for low speed and full speed operation. */ |
| 110 | #if (CONF_GCLK_USB_FREQUENCY > (48000000 + 48000000 / 400)) || (CONF_GCLK_USB_FREQUENCY < (48000000 - 48000000 / 400)) |
| 111 | #warning USB clock should be 48MHz ~ 0.25% clock, check your configuration! |
| 112 | #endif |
| 113 | |
| 114 | void USB_DEVICE_INSTANCE_CLOCK_init(void) |
| 115 | { |
| 116 | |
| 117 | hri_gclk_write_PCHCTRL_reg(GCLK, USB_GCLK_ID, CONF_GCLK_USB_SRC | GCLK_PCHCTRL_CHEN); |
| 118 | hri_mclk_set_AHBMASK_USB_bit(MCLK); |
| 119 | hri_mclk_set_APBBMASK_USB_bit(MCLK); |
| 120 | } |
| 121 | |
| 122 | void USB_DEVICE_INSTANCE_init(void) |
| 123 | { |
| 124 | USB_DEVICE_INSTANCE_CLOCK_init(); |
| 125 | usb_d_init(); |
| 126 | USB_DEVICE_INSTANCE_PORT_init(); |
| 127 | } |
| 128 | |
| 129 | void system_init(void) |
| 130 | { |
| 131 | init_mcu(); |
| 132 | |
| 133 | USB_DEVICE_INSTANCE_init(); |
| 134 | } |