Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SDK fixes for BL702 (EFUSE, USB, ADC, etc.) #145

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions components/usb/cherryusb/class/hid/usbd_hid.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ static int hid_class_interface_request_handler(struct usb_setup_packet *setup, u
switch (setup->bRequest) {
case HID_REQUEST_GET_REPORT:
/* report id ,report type */
(*data)[0] = usbh_hid_get_report(intf_num, LO_BYTE(setup->wValue), HI_BYTE(setup->wValue));
*len = 1;
usbh_hid_get_report(intf_num, LO_BYTE(setup->wValue), HI_BYTE(setup->wValue), data, len);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

must use return value

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't process long GET_REPORT requests while using return value. So the only way is to pass data and len pointers to the application usbh_hid_get_report() function. This issue present in original Cherry USB implementation, but we could change this in bouffalo_sdk to implement proper HID requests handling.

break;
case HID_REQUEST_GET_IDLE:
(*data)[0] = usbh_hid_get_idle(intf_num, LO_BYTE(setup->wValue));
Expand Down Expand Up @@ -61,7 +60,7 @@ struct usbd_interface *usbd_hid_init_intf(struct usbd_interface *intf, const uin
return intf;
}

__WEAK uint8_t usbh_hid_get_report(uint8_t intf, uint8_t report_id, uint8_t report_type)
__WEAK uint8_t usbh_hid_get_report(uint8_t intf, uint8_t report_id, uint8_t report_type, uint8_t **report, uint32_t *len)
{
return 0;
}
Expand All @@ -76,7 +75,7 @@ __WEAK uint8_t usbh_hid_get_protocol(uint8_t intf)
return 0;
}

__WEAK void usbh_hid_set_report(uint8_t intf, uint8_t report_id, uint8_t report_type, uint8_t *report, uint8_t report_len)
__WEAK void usbh_hid_set_report(uint8_t intf, uint8_t report_id, uint8_t report_type, uint8_t *report, uint16_t report_len)
{
}

Expand Down
4 changes: 2 additions & 2 deletions components/usb/cherryusb/class/hid/usbd_hid.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ void usbd_hid_descriptor_register(uint8_t intf_num, const uint8_t *desc);
void usbd_hid_report_descriptor_register(uint8_t intf_num, const uint8_t *desc, uint32_t desc_len);

/* Setup request command callback api */
uint8_t usbh_hid_get_report(uint8_t intf, uint8_t report_id, uint8_t report_type);
uint8_t usbh_hid_get_report(uint8_t intf, uint8_t report_id, uint8_t report_type, uint8_t **report, uint32_t *len);
uint8_t usbh_hid_get_idle(uint8_t intf, uint8_t report_id);
uint8_t usbh_hid_get_protocol(uint8_t intf);
void usbh_hid_set_report(uint8_t intf, uint8_t report_id, uint8_t report_type, uint8_t *report, uint8_t report_len);
void usbh_hid_set_report(uint8_t intf, uint8_t report_id, uint8_t report_type, uint8_t *report, uint16_t report_len);
void usbh_hid_set_idle(uint8_t intf, uint8_t report_id, uint8_t duration);
void usbh_hid_set_protocol(uint8_t intf, uint8_t protocol);

Expand Down
3 changes: 2 additions & 1 deletion drivers/lhal/include/bflb_adc.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
/** @defgroup ADC_CLK_DIV adc clock divison definition
* @{
*/
#define ADC_CLK_DIV_1 0

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

give up div1

Copy link
Author

@mdednev mdednev May 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, explain. This is valid divider value for ADC clock and I'm using it in my project.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

adc value is not inaccuracy in div1 in some cases.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, of course. But ADC speed should match external signal driver impedance to get proper signal sampling. So, it is up to board and software developer to select proper divider value for their signal parameters to get accurate ADC sampling and reading. So I suppose, that we should not limit this parameter in SDK if it is allowed in datasheet and reference manual and there is no restrictions in errata.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For div1, we will remove in datasheet.

#define ADC_CLK_DIV_4 1
#define ADC_CLK_DIV_8 2
#define ADC_CLK_DIV_12 3
Expand Down Expand Up @@ -183,7 +184,7 @@ void bflb_adc_link_rxdma(struct bflb_device_s *dev, bool enable);
* @param [in] channels pair number of channels
* @return Zero on success; a negated errno value on failure
*/
int bflb_adc_channel_config(struct bflb_device_s *dev, struct bflb_adc_channel_s *chan, uint8_t channels);
int bflb_adc_channel_config(struct bflb_device_s *dev, const struct bflb_adc_channel_s *chan, uint8_t channels);

/**
* @brief Start adc conversion
Expand Down
4 changes: 2 additions & 2 deletions drivers/lhal/include/bflb_mtimer.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ void bflb_mtimer_delay_us(uint32_t time);
*
* @return time with us
*/
uint64_t bflb_mtimer_get_time_us();
uint64_t bflb_mtimer_get_time_us(void);

/**
* @brief Get current mtimer time with ms.
*
* @return time with ms
*/
uint64_t bflb_mtimer_get_time_ms();
uint64_t bflb_mtimer_get_time_ms(void);

#ifdef __cplusplus
}
Expand Down
2 changes: 1 addition & 1 deletion drivers/lhal/include/bflb_pwm_v1.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef _BFLB_PWM_V1_H
#define _BFLB_PWM_V2_H
#define _BFLB_PWM_V1_H

#include "bflb_core.h"

Expand Down
18 changes: 9 additions & 9 deletions drivers/lhal/src/bflb_adc.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ void bflb_adc_link_rxdma(struct bflb_device_s *dev, bool enable)
putreg32(regval, ADC_GPIP_BASE + GPIP_GPADC_CONFIG_OFFSET);
}

int bflb_adc_channel_config(struct bflb_device_s *dev, struct bflb_adc_channel_s *chan, uint8_t channels)
int bflb_adc_channel_config(struct bflb_device_s *dev, const struct bflb_adc_channel_s *chan, uint8_t channels)
{
uint32_t regval;
uint32_t regval2;
Expand Down Expand Up @@ -462,21 +462,21 @@ void bflb_adc_parse_result(struct bflb_device_s *dev, uint32_t *buffer, struct b
conv_result = 4095;
}
result[i].value = conv_result;
result[i].millivolt = (float)result[i].value / 4096 * ref;
result[i].millivolt = (float)result[i].value / 4095.0f * ref;
} else if (resolution == ADC_RESOLUTION_14B) {
conv_result = (uint32_t)(((buffer[i] & 0xffff) >> 2) / coe);
if (conv_result > 16383) {
conv_result = 16383;
}
result[i].value = conv_result;
result[i].millivolt = (float)result[i].value / 16384 * ref;
result[i].millivolt = (float)result[i].value / 16383.0f * ref;
} else if (resolution == ADC_RESOLUTION_16B) {
conv_result = (uint32_t)((buffer[i] & 0xffff) / coe);
if (conv_result > 65535) {
conv_result = 65535;
}
result[i].value = conv_result;
result[i].millivolt = (int32_t)result[i].value / 65536.0 * ref;
result[i].millivolt = (int32_t)result[i].value / 65535.0f * ref;
} else {
}
}
Expand All @@ -499,21 +499,21 @@ void bflb_adc_parse_result(struct bflb_device_s *dev, uint32_t *buffer, struct b
conv_result = 2047;
}
result[i].value = conv_result;
result[i].millivolt = (float)result[i].value / 2048 * ref;
result[i].millivolt = (float)result[i].value / 2047 * ref;
} else if (resolution == ADC_RESOLUTION_14B) {
conv_result = (uint32_t)(((tmp & 0xffff) >> 2) / coe);
if (conv_result > 8191) {
conv_result = 8191;
}
result[i].value = conv_result;
result[i].millivolt = (float)result[i].value / 8192 * ref;
result[i].millivolt = (float)result[i].value / 8191 * ref;
} else if (resolution == ADC_RESOLUTION_16B) {
conv_result = (uint32_t)((tmp & 0xffff) / coe);
if (conv_result > 32767) {
conv_result = 32767;
}
result[i].value = conv_result;
result[i].millivolt = (float)result[i].value / 32768 * ref;
result[i].millivolt = (float)result[i].value / 32767 * ref;
} else {
}

Expand Down Expand Up @@ -613,9 +613,9 @@ float bflb_adc_tsen_get_temp(struct bflb_device_s *dev)
bflb_adc_parse_result(dev, &raw_data, &result, 1);
v1 = result.value;
if (v0 > v1) {
temp = (((float)v0 - (float)v1) - (float)tsen_offset) / 7.753;
temp = (((float)v0 - (float)v1) - (float)tsen_offset) / 7.753f;
} else {
temp = (((float)v1 - (float)v0) - (float)tsen_offset) / 7.753;
temp = (((float)v1 - (float)v0) - (float)tsen_offset) / 7.753f;
}

return temp;
Expand Down
Loading