Skip to content

Commit bfbe769

Browse files
zeonchewAlessandroLuo
authored andcommitted
mcu: apollo4p: usb: coding style changes
- Coding style changes according to ambiqsuite standard. - Moved definition of AM_HAL_USB_CTRL_XFR_WAIT_STATUS_ACK_ZLP_FROM_STACK to CMakefile for ease of porting of changes from new SDK releases. Signed-off-by: Chew Zeh Yang <[email protected]>
1 parent d341bdd commit bfbe769

File tree

3 files changed

+17
-21
lines changed

3 files changed

+17
-21
lines changed

mcu/apollo4p/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ endif()
6464

6565
if(CONFIG_AMBIQ_HAL_USE_USB)
6666
zephyr_library_sources(hal/am_hal_usb.c)
67+
add_compile_definitions(AM_HAL_USB_CTRL_XFR_WAIT_STATUS_ACK_ZLP_FROM_STACK)
6768
endif()
6869

6970
zephyr_include_directories(hal)

mcu/apollo4p/hal/am_hal_usb.c

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
//! The USB controller will send STATUS ACK to USB Host regardless of the
6868
//! selection.
6969
//
70-
#define AM_HAL_USB_CTRL_XFR_WAIT_STATUS_ACK_ZLP_FROM_STACK
70+
// #define AM_HAL_USB_CTRL_XFR_WAIT_STATUS_ACK_ZLP_FROM_STACK
7171

7272

7373
//*****************************************************************
@@ -238,10 +238,10 @@ typedef struct
238238
//! Endpoint transfer complete callback
239239
am_hal_usb_ep_xfer_complete_callback ep_xfer_complete_callback;
240240

241-
#ifndef AM_HAL_USB_CTRL_XFR_WAIT_STATUS_ACK_ZLP_FROM_STACK
241+
#ifndef AM_HAL_USB_CTRL_XFR_WAIT_STATUS_ACK_ZLP_FROM_STACK
242242
bool bPendingInEndData;
243243
bool bPendingOutEndData;
244-
#endif
244+
#endif
245245
}
246246
am_hal_usb_state_t;
247247

@@ -806,7 +806,6 @@ am_hal_usb_power_control(void *pHandle,
806806
bool bRetainState)
807807
{
808808

809-
810809
#ifndef AM_HAL_DISABLE_API_VALIDATION
811810
//
812811
// Check to make sure this is a valid handle.
@@ -822,7 +821,6 @@ am_hal_usb_power_control(void *pHandle,
822821
am_hal_usb_state_t *pState = (am_hal_usb_state_t *) pHandle;
823822
uint32_t ui32Module = pState->ui32Module;
824823

825-
826824
#ifndef AM_HAL_DISABLE_API_VALIDATION
827825
if ( ui32Module >= AM_REG_USB_NUM_MODULES )
828826
{
@@ -1852,9 +1850,9 @@ am_hal_usb_ep0_xfer(am_hal_usb_state_t *pState, uint8_t ui8EpNum, uint8_t ui8EpD
18521850

18531851
switch ( pState->eEP0State )
18541852
{
1855-
#ifndef AM_HAL_USB_CTRL_XFR_WAIT_STATUS_ACK_ZLP_FROM_STACK
1853+
#ifndef AM_HAL_USB_CTRL_XFR_WAIT_STATUS_ACK_ZLP_FROM_STACK
18561854
case AM_HAL_USB_EP0_STATE_IDLE:
1857-
if((pState->bPendingInEndData || pState->bPendingOutEndData) && (ui16Len == 0))
1855+
if ((pState->bPendingInEndData || pState->bPendingOutEndData) && (ui16Len == 0))
18581856
{
18591857
// Reset EP0 state and wait for the next command from host.
18601858
am_hal_usb_ep0_state_reset(pState);
@@ -1867,12 +1865,12 @@ am_hal_usb_ep0_xfer(am_hal_usb_state_t *pState, uint8_t ui8EpNum, uint8_t ui8EpD
18671865
return AM_HAL_STATUS_FAIL;
18681866
}
18691867
break;
1870-
#endif
1868+
#endif
18711869

18721870
case AM_HAL_USB_EP0_STATE_SETUP:
18731871
if (ui16Len == 0x0)
18741872
{
1875-
#ifndef AM_HAL_USB_CTRL_XFR_WAIT_STATUS_ACK_ZLP_FROM_STACK
1873+
#ifndef AM_HAL_USB_CTRL_XFR_WAIT_STATUS_ACK_ZLP_FROM_STACK
18761874
// There are 2 conditions that we are entering to this handling:
18771875
// 1. Previous command was with data stage. However, the subsequent SETUP is
18781876
// received in ISR before the ACK stage handling is done. For this case,
@@ -1881,7 +1879,7 @@ am_hal_usb_ep0_xfer(am_hal_usb_state_t *pState, uint8_t ui8EpNum, uint8_t ui8EpD
18811879
// back to IDLE so that it is able to receive next SETUP correctly.
18821880

18831881
// Case 1:
1884-
if(pState->bPendingOutEndData || pState->bPendingInEndData)
1882+
if (pState->bPendingOutEndData || pState->bPendingInEndData)
18851883
{
18861884
am_hal_usb_xfer_reset(&pState->ep0_xfer);
18871885
pState->bPendingOutEndData = false;
@@ -1898,7 +1896,7 @@ am_hal_usb_ep0_xfer(am_hal_usb_state_t *pState, uint8_t ui8EpNum, uint8_t ui8EpD
18981896
pState->eEP0State =
18991897
(ui8EpDir == AM_HAL_USB_EP_DIR_IN) ? AM_HAL_USB_EP0_STATE_STATUS_TX : AM_HAL_USB_EP0_STATE_STATUS_RX;
19001898
}
1901-
#else
1899+
#else
19021900
// Upper layer USB stack just use zero length packet to confirm no data stage
19031901
// some requests like CLEAR_FEARURE, SET_ADDRESS, SET_CONFIGRATION, etc.
19041902
// end the control transfer from device side
@@ -1908,7 +1906,7 @@ am_hal_usb_ep0_xfer(am_hal_usb_state_t *pState, uint8_t ui8EpNum, uint8_t ui8EpD
19081906
// Will indicate request is completed
19091907
pState->eEP0State =
19101908
(ui8EpDir == AM_HAL_USB_EP_DIR_IN) ? AM_HAL_USB_EP0_STATE_STATUS_TX : AM_HAL_USB_EP0_STATE_STATUS_RX;
1911-
#endif
1909+
#endif
19121910
}
19131911
else
19141912
{
@@ -1928,11 +1926,11 @@ am_hal_usb_ep0_xfer(am_hal_usb_state_t *pState, uint8_t ui8EpNum, uint8_t ui8EpD
19281926
// Read requests handling
19291927
case AM_HAL_USB_EP_DIR_IN:
19301928

1931-
#ifndef AM_HAL_USB_CTRL_XFR_WAIT_STATUS_ACK_ZLP_FROM_STACK
1929+
#ifndef AM_HAL_USB_CTRL_XFR_WAIT_STATUS_ACK_ZLP_FROM_STACK
19321930
// Flag that we need to handle End Data later for OUT
19331931
// direction
19341932
pState->bPendingOutEndData = true;
1935-
#endif
1933+
#endif
19361934

19371935
// Load the first packet
19381936
if (ui16Len < maxpacket)
@@ -1958,11 +1956,11 @@ am_hal_usb_ep0_xfer(am_hal_usb_state_t *pState, uint8_t ui8EpNum, uint8_t ui8EpD
19581956
// Write requests handling
19591957
// Waiting the host sending the data to the device
19601958

1961-
#ifndef AM_HAL_USB_CTRL_XFR_WAIT_STATUS_ACK_ZLP_FROM_STACK
1959+
#ifndef AM_HAL_USB_CTRL_XFR_WAIT_STATUS_ACK_ZLP_FROM_STACK
19621960
// Flag that we need to handle End Data later for IN
19631961
// direction
19641962
pState->bPendingInEndData = true;
1965-
#endif
1963+
#endif
19661964

19671965
pState->ep0_xfer.remaining = ui16Len;
19681966
pState->eEP0State = AM_HAL_USB_EP0_STATE_DATA_RX;
@@ -3099,8 +3097,8 @@ am_hal_usb_control(am_hal_usb_control_e eControl, void *pArgs)
30993097
ui32RetVal = AM_HAL_STATUS_INVALID_ARG;
31003098
break;
31013099
}
3102-
ui32RetVal = am_hal_usb_setHFRC2( *((am_hal_usb_hs_clock_type *) pArgs)) ;
3103-
break ;
3100+
ui32RetVal = am_hal_usb_setHFRC2( *((am_hal_usb_hs_clock_type *) pArgs));
3101+
break;
31043102

31053103
default:
31063104
ui32RetVal = AM_HAL_STATUS_INVALID_ARG;

mcu/apollo4p/hal/am_hal_usb.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,6 @@ typedef enum
157157
}
158158
am_hal_usb_xfer_code_e;
159159

160-
161160
//*****************************************************************************
162161
//
163162
//! @brief Enum for the USB control call
@@ -180,7 +179,6 @@ typedef enum
180179
//! this is how modules configure the HFRC2
181180
AM_HAL_CLKGEN_CONTROL_SET_HFRC2_TYPE,
182181

183-
184182
} am_hal_usb_control_e;
185183

186184
//*****************************************************************************
@@ -862,7 +860,6 @@ extern uint32_t am_hal_usb_control(am_hal_usb_control_e eControl, void *pArgs);
862860
//*****************************************************************************
863861
extern uint32_t am_hal_usb_setHFRC2(am_hal_usb_hs_clock_type tUsbHsClockType);
864862

865-
866863
//*****************************************************************************
867864
//
868865
//! @brief Reset EP State

0 commit comments

Comments
 (0)