mirror of
https://github.com/No-Chicken/Power-Pico.git
synced 2026-04-03 13:02:36 +08:00
update pd test
This commit is contained in:
@@ -12,9 +12,9 @@
|
||||
* FUSB302 can support PD3.0 with limitations and workarounds
|
||||
* - Do not have enough FIFO for unchunked message, use chunked message instead
|
||||
* - VBUS sense low threshold at 4V, disable vbus_sense if request PPS below 4V
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include <string.h>
|
||||
#include "FUSB302_UFP.h"
|
||||
|
||||
@@ -328,7 +328,7 @@ static FUSB302_ret_t FUSB302_state_unattached(FUSB302_dev_t *dev, FUSB302_event_
|
||||
/* clear interrupt */
|
||||
REG_READ(ADDRESS_INTERRUPTA, ®_INTERRUPTA, 2);
|
||||
dev->interrupta = 0;
|
||||
dev->interruptb = 0;
|
||||
dev->interruptb = 0;
|
||||
|
||||
/* enable tx on cc pin */
|
||||
if (dev->cc1 > 0) {
|
||||
@@ -358,7 +358,7 @@ static FUSB302_ret_t FUSB302_state_attached(FUSB302_dev_t *dev, FUSB302_event_t
|
||||
{
|
||||
REG_READ(ADDRESS_STATUS0A, ®_STATUS0A, 7);
|
||||
dev->interrupta |= REG_INTERRUPTA;
|
||||
dev->interruptb |= REG_INTERRUPTB;
|
||||
dev->interruptb |= REG_INTERRUPTB;
|
||||
if (dev->vbus_sense && ((REG_STATUS0 & VBUSOK) == 0)) {
|
||||
/* reset cc pins to pull down */
|
||||
REG_SWITCHES0 = PDWN1 | PDWN2;
|
||||
@@ -429,7 +429,7 @@ FUSB302_ret_t FUSB302_init(FUSB302_dev_t *dev)
|
||||
/* restore default settings */
|
||||
REG_RESET = SW_RES;
|
||||
REG_WRITE(ADDRESS_RESET, ®_RESET, 1);
|
||||
|
||||
|
||||
/* fetch all R/W registers */
|
||||
REG_READ(ADDRESS_DEVICE_ID, ®_DEVICE_ID, 15);
|
||||
|
||||
@@ -448,7 +448,7 @@ FUSB302_ret_t FUSB302_init(FUSB302_dev_t *dev)
|
||||
REG_MASK = 0xFF;
|
||||
REG_MASK &= ~(M_VBUSOK | M_ACTIVITY | M_COLLISION | M_ALERT | M_CRC_CHK);
|
||||
REG_WRITE(ADDRESS_MASK, ®_MASK, 1);
|
||||
|
||||
|
||||
/* configure interrupt maska/maskb */
|
||||
REG_MASKA = 0xFF;
|
||||
REG_MASKA &= ~(M_RETRYFAIL | M_HARDSENT | M_TXSENT | M_HARDRST);
|
||||
@@ -456,7 +456,7 @@ FUSB302_ret_t FUSB302_init(FUSB302_dev_t *dev)
|
||||
REG_MASKB = 0xFF;
|
||||
REG_MASKB &= ~(M_GCRCSENT);
|
||||
REG_WRITE(ADDRESS_MASKB, ®_MASKB, 1);
|
||||
|
||||
|
||||
/* enable interrupt */
|
||||
REG_CONTROL0 &= ~INT_MASK;
|
||||
REG_WRITE(ADDRESS_CONTROL0, ®_CONTROL0, 1);
|
||||
@@ -464,7 +464,7 @@ FUSB302_ret_t FUSB302_init(FUSB302_dev_t *dev)
|
||||
/* Power on, enable VUSB detection */
|
||||
REG_POWER = PWR_BANDGAP | PWR_RECEIVER | PWR_MEASURE;
|
||||
REG_WRITE(ADDRESS_POWER, ®_POWER, 1);
|
||||
|
||||
|
||||
dev->vbus_sense = 1;
|
||||
dev->err_msg = FUSB302_ERR_MSG("");
|
||||
return FUSB302_SUCCESS;
|
||||
@@ -489,7 +489,7 @@ FUSB302_ret_t FUSB302_set_vbus_sense(FUSB302_dev_t *dev, uint8_t enable)
|
||||
if (dev->vbus_sense != enable) {
|
||||
if (enable) {
|
||||
REG_MASK &= ~M_VBUSOK; /* enable VBUSOK interrupt */
|
||||
} else {
|
||||
} else {
|
||||
REG_MASK |= M_VBUSOK; /* disable VBUSOK interrupt */
|
||||
}
|
||||
REG_WRITE(ADDRESS_MASK, ®_MASK, 1);
|
||||
|
||||
@@ -2,11 +2,20 @@
|
||||
#include "i2c.h"
|
||||
#include "cmsis_os2.h"
|
||||
|
||||
#define clock_ms() xTaskGetTickCount()
|
||||
#define delay_ms(ms) osDelay(ms)
|
||||
#define FUSB302_USE_OS 1
|
||||
|
||||
#if FUSB302_USE_OS == 1
|
||||
#define clock_ms() osKernelGetTickCount()
|
||||
#define delay_ms(ms) osDelay(ms)
|
||||
#else
|
||||
#define clock_ms() HAL_GetTick()
|
||||
#define delay_ms(ms) HAL_Delay(ms)
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#define PD_POLLING 100
|
||||
#define TYPEC_SINK_WAIT_CAP 350
|
||||
#define TYPEC_SINK_WAIT_CAP 1500
|
||||
#define REQUEST_TO_PS_READY 580
|
||||
#define PPS_REQUEST 5000
|
||||
|
||||
@@ -14,8 +23,6 @@ FUSB302_dev_t fusb302_dev;
|
||||
PD_protocol_t pd_protocol;
|
||||
App_PD_t app_pd;
|
||||
|
||||
int res;
|
||||
|
||||
void fusb302_i2c_read(uint8_t dev_addr, uint8_t reg_addr, uint8_t *data, uint8_t count)
|
||||
{
|
||||
HAL_I2C_Mem_Read(&hi2c1, dev_addr, reg_addr, I2C_MEMADD_SIZE_8BIT, data, count, 10);
|
||||
@@ -36,7 +43,7 @@ void status_power_ready(status_power_t status, uint16_t voltage, uint16_t curren
|
||||
|
||||
void set_default_power(void)
|
||||
{
|
||||
status_power_ready(STATUS_POWER_TYP, PD_V(5), PD_A(1));
|
||||
status_power_ready(STATUS_POWER_TYP, PD_V(5.0), PD_A(1.0));
|
||||
}
|
||||
|
||||
void handle_protocol_event(PD_protocol_event_t events)
|
||||
@@ -171,7 +178,11 @@ uint8_t fusb302_dev_init(void) {
|
||||
fusb302_dev.i2c_address = 0x22<<1; // FUSB302 I2C address
|
||||
fusb302_dev.i2c_read = fusb302_i2c_read;
|
||||
fusb302_dev.i2c_write = fusb302_i2c_write;
|
||||
fusb302_dev.delay_ms = osDelay;
|
||||
#if FUSB302_USE_OS == 1
|
||||
fusb302_dev.delay_ms = osDelay;
|
||||
#else
|
||||
fusb302_dev.delay_ms = HAL_Delay;
|
||||
#endif
|
||||
if (FUSB302_init(&fusb302_dev) == FUSB302_SUCCESS && FUSB302_get_ID(&fusb302_dev, 0, 0) == FUSB302_SUCCESS) {
|
||||
PD_protocol_init(&pd_protocol);
|
||||
return 0;
|
||||
|
||||
@@ -69,6 +69,12 @@ void MX_GPIO_Init(void)
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pin : PB4 */
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_4;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||||
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN 2 */
|
||||
|
||||
@@ -10,8 +10,6 @@
|
||||
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
|
||||
uint8_t timer_flag = 0;
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
|
||||
/**
|
||||
@@ -24,12 +22,11 @@ void PDUFPTask(void *argument)
|
||||
// FUSB init
|
||||
fusb302_dev_init();
|
||||
// set
|
||||
PD_protocol_set_power_option(&pd_protocol, PD_POWER_OPTION_MAX_9V);
|
||||
PD_protocol_set_PPS(&pd_protocol, PD_V(8.4), PD_A(2.0), true);
|
||||
PD_protocol_set_power_option(&pd_protocol, PD_POWER_OPTION_MAX_VOLTAGE);
|
||||
PD_protocol_set_PPS(&pd_protocol, PD_V(8.4), PD_A(2.0), false);
|
||||
while(1)
|
||||
{
|
||||
timer_flag = fusb302_timer();
|
||||
if (timer_flag) {
|
||||
if (fusb302_timer() || HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_4) == GPIO_PIN_RESET) {
|
||||
FUSB302_event_t FUSB302_events = 0;
|
||||
for (uint8_t i = 0; i < 3 && FUSB302_alert(&fusb302_dev, &FUSB302_events) != FUSB302_SUCCESS; i++) {}
|
||||
if (FUSB302_events) {
|
||||
@@ -37,6 +34,6 @@ void PDUFPTask(void *argument)
|
||||
}
|
||||
}
|
||||
|
||||
osDelay(100);
|
||||
osDelay(50);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user