Skip to content
Snippets Groups Projects
Commit 5a2db7c3 authored by Marco Tinner's avatar Marco Tinner
Browse files

first running version

parent 111ba2de
Branches
Tags
No related merge requests found
......@@ -28,12 +28,16 @@ void init(void) {
int main(void) {
sei();
init();
U8 count = 0;
uart_write_string("start\n\r");
uart_trigger_send();
for(;;) {
uart_write_string("heartbeat\n\r");
count++;
uart_write_string("heartbeat ");
uart_writeNumber(count);
uart_write_string("\n\r");
uart_trigger_send();
_delay_ms(1000);
}
......
......@@ -19,13 +19,13 @@
//********** USB device descriptor values **********//
#define USB_DD_bcdUSB 0x0200 // USB specification number
#define USB_DD_bDeviceClass 0x02 // Device class (vendor specific)
#define USB_DD_bDeviceClass 0x00 // Device class (vendor specific)
#define USB_DD_bDevcieSubClass 0x00 // Device subclass (vendor specific)
#define USB_DD_bDeviceProtocol 0x00 // Device protocol (vendor specific)
#define USB_DD_bMaxPacketSize0 32 // Maximum packet size for endpoint zero
#define USB_DD_bMaxPacketSize0 64 // Maximum packet size for endpoint zero
#define USB_DD_idVendor 0x0403 // Vendor ID (NTB)
#define USB_DD_idProduct 0x6001 // Product ID (inf usb-expboard) 6001
#define USB_DD_bcdDevice 0x1000 // Device release number
#define USB_DD_bcdDevice 0x0600 // Device release number
#define USB_DD_iManufacturer 0x01 // Index of manufacturer string descriptor
#define USB_DD_iProduct 0x02 // Index of product string descriptor
#define USB_DD_iSerialNumber 0x03 // Index of serial number string descriptor
......@@ -33,7 +33,7 @@
//********** Configuration definitions **********//
#define USB_CONF1_bNumInterfaces 2 // Number of interfaces
#define USB_CONF1_bNumInterfaces 1 // Number of interfaces
#define USB_CONF1_bConfigurationValue 1 // Index of this configuration
#define USB_CONF1_iConfiguration 0 // Index of String descriptor
#define USB_CONF1_bmAttributes USB_CONF_SELFPOWERED
......@@ -43,57 +43,37 @@
#define USB_INT1_bInteraceNumber 0 // Number (identifier) of interface
#define USB_INT1_bAlternateSetting 0 // Value to select alternate setting
#define USB_INT1_bNumEndpoints 1 // Number of endpoints
#define USB_INT1_bInterfaceClass 0x02 // Interface class
#define USB_INT1_bInterfaceSubClass 0x02 // Interface sub class
#define USB_INT1_bInterfaceProtocol 0x01 // Interface protocol
#define USB_INT1_bNumEndpoints 2 // Number of endpoints
#define USB_INT1_bInterfaceClass 0xFF // Interface class
#define USB_INT1_bInterfaceSubClass 0xFF // Interface sub class
#define USB_INT1_bInterfaceProtocol 0xFF // Interface protocol
#define USB_INT1_iInterface 0 // Index of String descriptor
#define USB_INT2_bInteraceNumber 1 // Number (identifier) of interface
#define USB_INT2_bAlternateSetting 0 // Value to select alternate setting
#define USB_INT2_bNumEndpoints 2 // Number of endpoints
#define USB_INT2_bInterfaceClass 0x0A // Interface class
#define USB_INT2_bInterfaceSubClass 0x00 // Interface sub class
#define USB_INT2_bInterfaceProtocol 0x00 // Interface protocol
#define USB_INT2_iInterface 0 // Index of String descriptor
//********** Endpoint definitions **********//
#define USB_EP_TOTAL_NUM 3 // Total number of endpoints (excluding ep zero)
#define USB_EP_TOTAL_NUM 2 // Total number of endpoints (excluding ep zero)
// device values
#define USB_EP1_NUM EP_1 // Endpoint number (identifier)
#define USB_EP1_TYPE USB_EP_TYPE_INTERRUPT // Endpoint Type
#define USB_EP1_TYPE USB_EP_TYPE_BULK // Endpoint Type
#define USB_EP1_DIR USB_EP_DIR_IN
#define USB_EP1_SIZE EP_SIZE_64
// descriptor values
#define USB_EP1_bEndpointAddress (USB_EP1_NUM | USB_EP_DIR_INbm) // Endpoint address
#define USB_EP1_bmAttributes USB_EP1_TYPE // Transfer type
#define USB_EP1_wMaxPacketSize 64 // Maximum packet size
#define USB_EP1_bInterval 0xFF // Interval for polling endpoint (only for INTERRUPT)
#define USB_EP1_bInterval 0x00 // Interval for polling endpoint (only for INTERRUPT)
// device values
#define USB_EP2_NUM EP_2 // Endpoint number (identifier)
#define USB_EP2_TYPE USB_EP_TYPE_BULK // Endpoint Type
#define USB_EP2_DIR USB_EP_DIR_IN
#define USB_EP2_DIR USB_EP_DIR_OUT
#define USB_EP2_SIZE EP_SIZE_64
// descriptor values
#define USB_EP2_bEndpointAddress (USB_EP2_NUM | USB_EP_DIR_INbm) // Endpoint address
#define USB_EP2_bEndpointAddress USB_EP2_NUM // Endpoint address
#define USB_EP2_bmAttributes USB_EP2_TYPE // Transfer type
#define USB_EP2_wMaxPacketSize 64 // Maximum packet size
#define USB_EP2_bInterval 0x00 // Interval for polling endpoint (only for INTERRUPT)
// device values
#define USB_EP3_NUM EP_3 // Endpoint number (identifier)
#define USB_EP3_TYPE USB_EP_TYPE_BULK // Endpoint Type
#define USB_EP3_DIR USB_EP_DIR_OUT
#define USB_EP3_SIZE EP_SIZE_64
// descriptor values
#define USB_EP3_bEndpointAddress USB_EP3_NUM // Endpoint address
#define USB_EP3_bmAttributes USB_EP3_TYPE // Transfer type
#define USB_EP3_wMaxPacketSize 64 // Maximum packet size
#define USB_EP3_bInterval 0x00 // Interval for polling endpoint (only for INTERRUPT)
//********** HID definitions **********//
/*
#define USB_HID_bscHID 0x1001 // HID specification number
......@@ -190,14 +170,8 @@ typedef struct {
typedef struct {
Usb_desc_config config;
Usb_desc_interface comInterface;
Usb_header_desc_hid header;
Usb_abstract_ctr_model_desc_hid abCtrMod;
Usb_union_desc_hid unionDesc;
Usb_call_management_desc_hid callManagement;
Usb_desc_endpoint ep1;
Usb_desc_interface dataInterface;
Usb_desc_endpoint ep2;
Usb_desc_endpoint ep3;
} Usb_desc_config_device;
//********** USB action hooks **********//
......
......@@ -135,31 +135,15 @@ U8 get_endpoint_nr_from_irq(){
void handleEPControlIRQ(){
if (Is_usb_receive_setup())
{
uart_write_string("Setup ");
usb_process_request();
Usb_ack_receive_setup();
}
if(Is_usb_in_ready())
{
uart_write_string("In");
Usb_ack_in_ready();
}
if(Is_usb_receive_out())
{
uart_write_string("Out");
Usb_ack_receive_out();
}
}
void handelEP1IRQ(){
if(Is_usb_in_ready())
{
uart_write_string("In");
//Usb_send_control_in();
Usb_send_control_in();
uint16_t bytesToSend = uart_avail_read();
if(bytesToSend>0){
uint16_t i = 0;
......@@ -180,16 +164,16 @@ void handelEP1IRQ(){
void handelEP2IRQ(){
if(Is_usb_receive_out())
{
uart_write_string("Out");
Usb_ack_receive_out();
uint16_t bytesToReceive = Usb_frame_number();
Usb_ack_control_out();
uint16_t bytesToReceive = Usb_byte_counter();
if(bytesToReceive>0){
uint16_t i = 0;
while(i < bytesToReceive){
uart_write(Usb_read_byte());
i++;
}
}
}
Usb_ack_receive_out();
}
}
......@@ -207,21 +191,16 @@ void handelEPIRQ(U8 ep){
ISR(USB_COM_vect){
U8 ep = 0;
uart_write_string("Controller Interrupt: ");
while(UEINT != 0){
ep = get_endpoint_nr_from_irq();
Usb_select_endpoint(ep);
switch(ep){
case EP_CONTROL:
handleEPControlIRQ();
//UEINTX = 0;
break;
case EP_1:
uart_write_string("EP: ");
uart_writeNumber(ep);
uart_write_string(" ");
handelEP1IRQ();
break;
case EP_2:
......@@ -243,15 +222,11 @@ ISR(USB_COM_vect){
handelEPIRQ(ep);
break;
}
//UEINTX = 0;
uart_write_string(", ");
}
uart_write_string("\n\r");
}
void handleVbusTransition(){
uart_write_string("VBUS plug-in detection, ");
//uart_write_string("VBUS plug-in detection, ");
if (Is_usb_vbus_high()){
Usb_enable_pad_regulator();
Config_pll(PLLx06);
......@@ -277,12 +252,12 @@ ISR (USB_GEN_vect)
if(Is_usb_id_transition()){
//This shouldn't happen
uart_write_string("USB ID Pad change detection, ");
uart_write_string("USB ID Pad change detection, ");
Usb_ack_id_transition();
}
if (Is_usb_sof()){
uart_write_string("Start of frame, ");
//uart_write_string("Start of frame, ");
Usb_ack_sof();
}
......@@ -332,27 +307,15 @@ ISR (USB_GEN_vect)
Usb_enable_endpoint();
usb_configure_endpoint(USB_EP2_NUM, USB_EP2_TYPE, USB_EP2_DIR, USB_EP2_SIZE, EP_ONE_BANK, EP_NYET_ENABLED);
Usb_enable_receive_out_interrupt();
// Endpoint 3
Usb_select_endpoint(USB_EP3_NUM);
Usb_enable_endpoint();
usb_configure_endpoint(USB_EP3_NUM, USB_EP3_TYPE, USB_EP3_DIR, USB_EP3_SIZE, EP_ONE_BANK, EP_NYET_ENABLED);
Usb_reset_endpoint(EP_CONTROL);
Usb_reset_endpoint(USB_EP1_NUM);
Usb_reset_endpoint(USB_EP2_NUM);
Usb_reset_endpoint(USB_EP3_NUM);
Usb_ack_reset();
}
uart_write_string("\n\r");
}
\ No newline at end of file
......@@ -28,17 +28,10 @@ const Usb_desc_config_device usb_desc_config = {
{
sizeof(Usb_desc_config)
, USB_DT_CONFIG
, sizeof(Usb_desc_config)
+ sizeof(Usb_desc_interface)
+ sizeof(Usb_header_desc_hid)
+ sizeof(Usb_abstract_ctr_model_desc_hid)
+ sizeof(Usb_union_desc_hid)
+ sizeof(Usb_call_management_desc_hid)
+ sizeof(Usb_desc_endpoint)
, sizeof(Usb_desc_config)
+ sizeof(Usb_desc_interface)
+ sizeof(Usb_desc_endpoint)
+ sizeof(Usb_desc_endpoint)
, USB_CONF1_bNumInterfaces
, USB_CONF1_bConfigurationValue
, USB_CONF1_iConfiguration
......@@ -46,7 +39,7 @@ const Usb_desc_config_device usb_desc_config = {
, USB_CONF1_MaxPower
}
,
{ //Comunication Interface
{ //Interface
sizeof(Usb_desc_interface)
, USB_DT_INTERFACE
, USB_INT1_bInteraceNumber
......@@ -58,37 +51,7 @@ const Usb_desc_config_device usb_desc_config = {
, USB_INT1_iInterface
}
,
{ //Header Functional
sizeof(Usb_header_desc_hid)
, USB_DT_CS_INTERFACE
, USB_ST_HEADER
, 272
}
,
{ //Abstract Control Model Functional
sizeof(Usb_abstract_ctr_model_desc_hid)
, USB_DT_CS_INTERFACE
, USB_ST_ABSTR_CTR
, 0x2
}
,
{ //Union Functional
sizeof(Usb_union_desc_hid)
, USB_DT_CS_INTERFACE
, USB_ST_UNION
, 0x0
, 0x0
}
,
{ //Call Management Functional
sizeof(Usb_call_management_desc_hid)
, USB_DT_CS_INTERFACE
, USB_ST_CALL_MANG
, 0x0
, 0x1
}
,
{ //Endpoint 1 (Interrupt IN)
{ //Endpoint 1 (Bulk IN)
sizeof(Usb_desc_endpoint)
, USB_DT_ENDPOINT
, USB_EP1_bEndpointAddress
......@@ -97,19 +60,7 @@ const Usb_desc_config_device usb_desc_config = {
, USB_EP1_bInterval
}
,
{ //Data Interface
sizeof(Usb_desc_interface)
, USB_DT_INTERFACE
, USB_INT2_bInteraceNumber
, USB_INT2_bAlternateSetting
, USB_INT2_bNumEndpoints
, USB_INT2_bInterfaceClass
, USB_INT2_bInterfaceSubClass
, USB_INT2_bInterfaceProtocol
, USB_INT2_iInterface
}
,
{ //Endpoint 2 (Bulk IN)
{ //Endpoint 2 (Bulk OUT)
sizeof(Usb_desc_endpoint)
, USB_DT_ENDPOINT
, USB_EP2_bEndpointAddress
......@@ -117,15 +68,6 @@ const Usb_desc_config_device usb_desc_config = {
, USB_EP2_wMaxPacketSize
, USB_EP2_bInterval
}
,
{ //Endpoint 3 (Bulk OUT)
sizeof(Usb_desc_endpoint)
, USB_DT_ENDPOINT
, USB_EP3_bEndpointAddress
, USB_EP3_bmAttributes
, USB_EP3_wMaxPacketSize
, USB_EP3_bInterval
}
};
const Usb_desc_string_manufacturer usb_desc_string_manufacturer = {
......
......@@ -61,7 +61,6 @@ void usb_process_request(void) {
switch (bmRequest) {
case GET_DESCRIPTOR:
if (0x80 == bmRequestType) {
uart_write_string("get descriptor ");
usb_get_descriptor();
} else {
usb_device_read_request(bmRequestType, bmRequest);
......@@ -69,16 +68,13 @@ void usb_process_request(void) {
break;
case GET_CONFIGURATION:
if (0x80 == bmRequestType) {
uart_write_string("get configuration ");
usb_get_configuration();
} else {
usb_device_read_request(bmRequestType, bmRequest);
}
break;
case SET_ADDRESS:
if (0x00 == bmRequestType) {
uart_write_string("set address ");
usb_set_address();
} else {
usb_device_read_request(bmRequestType, bmRequest);
......@@ -86,7 +82,6 @@ void usb_process_request(void) {
break;
case SET_CONFIGURATION:
if (0x00 == bmRequestType) {
uart_write_string("set configuration ");
usb_set_configuration();
} else {
......@@ -95,7 +90,6 @@ void usb_process_request(void) {
break;
case CLEAR_FEATURE:
if (0x02 == bmRequestType) {
uart_write_string("clear feature ");
usb_clear_feature();
} else {
usb_device_read_request(bmRequestType, bmRequest);
......@@ -104,14 +98,12 @@ void usb_process_request(void) {
case SET_FEATURE:
if (0x02 == bmRequestType) {
usb_set_feature();
uart_write_string("set feature ");
} else {
usb_device_read_request(bmRequestType, bmRequest);
}
break;
case GET_STATUS:
if ((0x7F < bmRequestType) & (0x82 >= bmRequestType)) {
uart_write_string("get status ");
usb_get_status();
} else {
usb_device_read_request(bmRequestType, bmRequest);
......@@ -119,7 +111,6 @@ void usb_process_request(void) {
break;
case GET_INTERFACE:
if (bmRequestType == 0x81) {
uart_write_string("get interface ");
usb_get_interface();
} else {
usb_device_read_request(bmRequestType, bmRequest);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment