Skip to content

Commit

Permalink
格式化USB部分代码
Browse files Browse the repository at this point in the history
  • Loading branch information
jim-kirisame committed Jun 9, 2019
1 parent d54e193 commit 9c0a781
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 153 deletions.
24 changes: 9 additions & 15 deletions usb/app_timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,14 @@ uint8_t pos = 0;
*/
void timer_tick()
{
for (int i = 0; i < pos; i++)
{
timer_info *timer = &timers[i];
if (timer->is_start)
{
for (int i = 0; i < pos; i++) {
timer_info* timer = &timers[i];
if (timer->is_start) {
timer->time_count++;
if (timer->time_count >= timer->period)
{
if (timer->time_count >= timer->period) {
timer->time_count = 0;
timer->exec_flag = true;
if (!timer->repeat)
{
if (!timer->repeat) {
timer->is_start = false;
}
}
Expand All @@ -52,11 +48,9 @@ void timer_tick()
*/
void timer_task_exec()
{
for (int i = 0; i < pos; i++)
{
timer_info *timer = &timers[i];
if (timer->exec_flag)
{
for (int i = 0; i < pos; i++) {
timer_info* timer = &timers[i];
if (timer->exec_flag) {
(*(timer->task))();
timer->exec_flag = false;
}
Expand All @@ -72,7 +66,7 @@ void timer_task_exec()
*/
void timer_create(task_t task, bool repeat, uint16_t period)
{
timer_info *timer = &timers[pos++];
timer_info* timer = &timers[pos++];
timer->exec_flag = false;
timer->is_start = true;
timer->period = period;
Expand Down
27 changes: 11 additions & 16 deletions usb/descriptor.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

#include <stdint.h>
#include "usb_descriptor.h"
#include <stdint.h>
// #include <stdio.h>

/** \brief 获取文本描述符
Expand All @@ -26,11 +26,10 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
* \return uint8_t 文本描述符长度
*
*/
static uint8_t getStringDescriptor(uint8_t order, uint8_t **strPtor)
static uint8_t getStringDescriptor(uint8_t order, uint8_t** strPtor)
{
uint8_t header = 0, strlen = 0;
do
{
do {
header += strlen;
if (header >= sizeof(StringDescriptor)) // 超过长度就直接返回
{
Expand All @@ -39,7 +38,7 @@ static uint8_t getStringDescriptor(uint8_t order, uint8_t **strPtor)
strlen = StringDescriptor[header];
} while (order--);

*strPtor = (uint8_t *)&StringDescriptor[header];
*strPtor = (uint8_t*)&StringDescriptor[header];
return strlen;
}

Expand All @@ -52,19 +51,18 @@ static uint8_t getStringDescriptor(uint8_t order, uint8_t **strPtor)
* \return uint8_t 是否为最后一个描述符
*
*/
uint8_t GetUsbDescriptor(uint8_t type1, uint8_t type2, uint8_t index, uint8_t *len, uint8_t **strPtr)
uint8_t GetUsbDescriptor(uint8_t type1, uint8_t type2, uint8_t index, uint8_t* len, uint8_t** strPtr)
{
// printf_tiny("getDesc:%x, %x\n", type1, type2);
switch (type1)
{
switch (type1) {
/**< 设备描述符 */
case 1:
*strPtr = (uint8_t *)&DeviceDescriptor[0];
*strPtr = (uint8_t*)&DeviceDescriptor[0];
*len = sizeof(DeviceDescriptor);
break;
/**< 配置描述符 */
case 2:
*strPtr = (uint8_t *)&ConfigDescriptor[0];
*strPtr = (uint8_t*)&ConfigDescriptor[0];
*len = sizeof(ConfigDescriptor);
break;
/**< 字符串描述符 */
Expand All @@ -73,17 +71,14 @@ uint8_t GetUsbDescriptor(uint8_t type1, uint8_t type2, uint8_t index, uint8_t *l
break;
/**< HID 报告描述符 */
case 0x22:
if (index < sizeof(ReportDescriptor))
{
if (index < sizeof(ReportDescriptor)) {
*strPtr = ReportDescriptor[index].pointer;
*len = ReportDescriptor[index].length;

if (index == sizeof(ReportDescriptor) - 1)
{
if (index == sizeof(ReportDescriptor) - 1) {
return 1; // 设备准备就绪
}
}
else // 接口超出上限
} else // 接口超出上限
{
*len = 0xff;
}
Expand Down
Loading

0 comments on commit 9c0a781

Please sign in to comment.