-
-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathusb_io.hpp
109 lines (85 loc) · 2.6 KB
/
usb_io.hpp
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
#pragma once
//=====================================================================//
/*! @file
@brief USB I/O 制御クラス
@author 平松邦仁 (hira@rvf-rc45.net)
@copyright Copyright (C) 2020 Kunihito Hiramatsu @n
Released under the MIT license @n
https://github.com/hirakuni45/RX/blob/master/LICENSE
*/
//=====================================================================//
#include "common/renesas.hpp"
#include "r_usb_basic_if.h"
extern "C" {
void usb_hstd_usb_handler(void);
void hw_usb_pclear_sts_resm(void);
};
namespace device {
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
/*!
@brief USB 基本I/O制御クラス
@param[in] USB_CH USB チャネル
*/
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
template <class USB_CH>
class usb_io {
typedef utils::format format;
ICU::LEVEL ilvl_;
ICU::VECTOR ivec_;
int32_t event_;
uint32_t cnt_;
static INTERRUPT_FUNC void i_task_()
{
usb_hstd_usb_handler(); /* Call interrupt routine */
}
static INTERRUPT_FUNC void r_task_()
{
/// hw_usb_pclear_sts_resm();
/// ICU.IPR[ilvl_] = 0x00; /* Priority Resume1=0 */
/// ICU.IR[ilvl_] = 0; /* Interrupt Request USB_resume USBR0 Clear */
}
public:
//-----------------------------------------------------------------//
/*!
@brief コンストラクター
*/
//-----------------------------------------------------------------//
usb_io() : ilvl_(ICU::LEVEL::NONE), ivec_(ICU::VECTOR::NONE),
event_(-1)
{ }
//-----------------------------------------------------------------//
/*!
@brief 開始
@param[in] ilvl 割り込みレベル
@return 正常なら「true」
*/
//-----------------------------------------------------------------//
bool start(ICU::LEVEL ilvl) noexcept
{
ilvl_ = ilvl;
// VBUSEN, OVERCURA ピンの設定
if(!port_map::turn(USB_CH::PERIPHERAL)) {
return false;
}
return true;
}
void enable_mod(bool ena = true) noexcept
{
format("USB0: enable_mod (%d)...\n") % static_cast<int>(ena);
power_mgr::turn(USB_CH::PERIPHERAL, ena);
}
void init_intr() noexcept
{
auto no = USB_CH::I_VEC;
ivec_ = icu_mgr::set_interrupt(no, i_task_, ilvl_);
format("USB0: init_intr(Vec: %d, No: %d, Lvl: %d)...\n")
% static_cast<int>(ivec_) % static_cast<int>(no) % static_cast<int>(ilvl_);
}
void enable_intr(bool ena = true) noexcept
{
/// format("USB0: enable_intr(%d)...\n") % static_cast<int>(ena);
ICU::IER.enable(ivec_, ena);
}
};
// template <class USB_CH> volatile uint32_t usb_io<USB_CH>::int_cnt_ = 0;
}