-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
18f6a51
commit 80b1b1f
Showing
29 changed files
with
4,583 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,3 +20,5 @@ setup.sh | |
.vs/ | ||
CMakeSettings.json | ||
|
||
# Language Server | ||
.clangd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
/****************************************************************************** | ||
* * | ||
* Copyright (C) 2024 MachineWare GmbH * | ||
* All Rights Reserved * | ||
* * | ||
* This is work is licensed under the terms described in the LICENSE file * | ||
* found in the root directory of this source tree. * | ||
* * | ||
******************************************************************************/ | ||
|
||
#ifndef VCML_USB_DEVICE_H | ||
#define VCML_USB_DEVICE_H | ||
|
||
#include "vcml/core/types.h" | ||
#include "vcml/core/systemc.h" | ||
#include "vcml/core/module.h" | ||
#include "vcml/core/model.h" | ||
|
||
#include "vcml/protocols/usb.h" | ||
|
||
namespace vcml { | ||
namespace usb { | ||
|
||
struct endpoint_desc { | ||
u8 address; | ||
u8 attributes; | ||
u16 max_packet_size; | ||
u8 interval; | ||
u8 refresh; | ||
u8 sync_address; | ||
vector<u8> extra; | ||
}; | ||
|
||
struct interface_desc { | ||
u8 alternate_setting; | ||
u8 ifxclass; | ||
u8 subclass; | ||
u8 protocol; | ||
vector<endpoint_desc> endpoints; | ||
vector<u8> extra; | ||
}; | ||
|
||
struct config_desc { | ||
u8 value; | ||
u8 attributes; | ||
u8 max_power; | ||
vector<interface_desc> interfaces; | ||
}; | ||
|
||
struct device_desc { | ||
u16 bcd_usb; | ||
u8 device_class; | ||
u8 device_subclass; | ||
u8 device_protocol; | ||
u8 max_packet_size0; | ||
u16 vendor_id; | ||
u16 product_id; | ||
u16 bcd_device; | ||
string manufacturer; | ||
string product; | ||
string serial_number; | ||
vector<config_desc> configs; | ||
}; | ||
|
||
class device : public module, public usb_dev_if | ||
{ | ||
private: | ||
u32 m_address; | ||
bool m_stalled; | ||
|
||
enum device_state { | ||
STATE_DEFAULT = 0, | ||
STATE_ADDRESSED = 1, | ||
STATE_CONFIGURED = 2, | ||
}; | ||
|
||
device_state m_state; | ||
|
||
enum control_state { | ||
STATE_SETUP, | ||
STATE_DATA, | ||
STATE_STATUS, | ||
}; | ||
|
||
struct ep0 { | ||
u16 req; | ||
u16 val; | ||
u16 idx; | ||
u16 len; | ||
size_t pos; | ||
usb_result res; | ||
control_state state; | ||
u8* ptr; | ||
u8 buf[1024]; | ||
} m_ep0; | ||
|
||
public: | ||
bool is_addressed() const { return m_state >= STATE_ADDRESSED; } | ||
bool is_configured() const { return m_state >= STATE_CONFIGURED; } | ||
|
||
u32 get_address() const { return m_address; } | ||
|
||
device(const sc_module_name& nm, const device_desc& desc); | ||
virtual ~device(); | ||
VCML_KIND(usb::device); | ||
|
||
protected: | ||
device_desc m_desc; | ||
size_t m_cur_config; | ||
size_t m_cur_iface; | ||
|
||
virtual usb_result get_data(u32 ep, u8* data, size_t len); | ||
virtual usb_result set_data(u32 ep, const u8* data, size_t len); | ||
|
||
virtual usb_result get_configuration(u8& config); | ||
virtual usb_result set_configuration(u8 config); | ||
virtual usb_result get_interface(u8& interface); | ||
virtual usb_result get_descriptor(u8 type, u8 idx, u8* data, size_t size); | ||
|
||
virtual usb_result handle_control(u16 req, u16 val, u16 idx, u8* data, | ||
size_t length); | ||
virtual usb_result handle_ep0(usb_packet& p); | ||
virtual usb_result handle_data(usb_packet& p); | ||
|
||
virtual void usb_reset_device() override; | ||
virtual void usb_reset_endpoint(int ep) override; | ||
virtual void usb_transport(usb_packet& p) override; | ||
}; | ||
|
||
} // namespace usb | ||
} // namespace vcml | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/****************************************************************************** | ||
* * | ||
* Copyright (C) 2024 MachineWare GmbH * | ||
* All Rights Reserved * | ||
* * | ||
* This is work is licensed under the terms described in the LICENSE file * | ||
* found in the root directory of this source tree. * | ||
* * | ||
******************************************************************************/ | ||
|
||
#ifndef VCML_USB_KEYBOARD_H | ||
#define VCML_USB_KEYBOARD_H | ||
|
||
#include "vcml/core/types.h" | ||
#include "vcml/core/systemc.h" | ||
#include "vcml/core/module.h" | ||
#include "vcml/core/model.h" | ||
|
||
#include "vcml/ui/input.h" | ||
#include "vcml/ui/keymap.h" | ||
#include "vcml/ui/console.h" | ||
|
||
#include "vcml/protocols/usb.h" | ||
#include "vcml/models/usb/device.h" | ||
|
||
namespace vcml { | ||
namespace usb { | ||
|
||
class keyboard : public device | ||
{ | ||
private: | ||
u8 m_leds; | ||
vector<u8> m_keys; | ||
|
||
ui::keyboard m_keyboard; | ||
ui::console m_console; | ||
|
||
void poll_modifier_keys(u8& data); | ||
void poll_standard_keys(u8* data, size_t len); | ||
void poll_keys(u8* data, size_t len); | ||
|
||
public: | ||
enum led_type { | ||
LED_NUM_LOCK = bit(0), | ||
LED_CAPS_LOCK = bit(1), | ||
LED_SCROLL_LOCK = bit(2), | ||
LED_COMPOSE = bit(3), | ||
LED_KANA = bit(4), | ||
}; | ||
|
||
constexpr bool get_led(led_type type) const { return m_leds & type; } | ||
|
||
property<bool> usb3; | ||
|
||
property<u16> vendorid; | ||
property<u16> productid; | ||
|
||
property<string> manufacturer; | ||
property<string> product; | ||
property<string> serialno; | ||
property<string> keymap; | ||
|
||
usb_target_socket usb_in; | ||
|
||
keyboard(const sc_module_name& nm); | ||
virtual ~keyboard(); | ||
VCML_KIND(usb::keyboard); | ||
|
||
protected: | ||
virtual void start_of_simulation() override; | ||
virtual void end_of_simulation() override; | ||
|
||
virtual usb_result get_report(u8* data, size_t size); | ||
virtual usb_result set_report(u8* data, size_t size); | ||
|
||
virtual usb_result get_data(u32 ep, u8* data, size_t len) override; | ||
|
||
usb_result get_interface_descriptor(u8 type, u8 idx, u8* data, size_t sz); | ||
|
||
virtual usb_result handle_control(u16 req, u16 val, u16 idx, u8* data, | ||
size_t length) override; | ||
}; | ||
|
||
} // namespace usb | ||
} // namespace vcml | ||
|
||
#endif |
Oops, something went wrong.