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:
@@ -2,11 +2,20 @@
|
|||||||
#include "i2c.h"
|
#include "i2c.h"
|
||||||
#include "cmsis_os2.h"
|
#include "cmsis_os2.h"
|
||||||
|
|
||||||
#define clock_ms() xTaskGetTickCount()
|
#define FUSB302_USE_OS 1
|
||||||
|
|
||||||
|
#if FUSB302_USE_OS == 1
|
||||||
|
#define clock_ms() osKernelGetTickCount()
|
||||||
#define delay_ms(ms) osDelay(ms)
|
#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 PD_POLLING 100
|
||||||
#define TYPEC_SINK_WAIT_CAP 350
|
#define TYPEC_SINK_WAIT_CAP 1500
|
||||||
#define REQUEST_TO_PS_READY 580
|
#define REQUEST_TO_PS_READY 580
|
||||||
#define PPS_REQUEST 5000
|
#define PPS_REQUEST 5000
|
||||||
|
|
||||||
@@ -14,8 +23,6 @@ FUSB302_dev_t fusb302_dev;
|
|||||||
PD_protocol_t pd_protocol;
|
PD_protocol_t pd_protocol;
|
||||||
App_PD_t app_pd;
|
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)
|
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);
|
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)
|
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)
|
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_address = 0x22<<1; // FUSB302 I2C address
|
||||||
fusb302_dev.i2c_read = fusb302_i2c_read;
|
fusb302_dev.i2c_read = fusb302_i2c_read;
|
||||||
fusb302_dev.i2c_write = fusb302_i2c_write;
|
fusb302_dev.i2c_write = fusb302_i2c_write;
|
||||||
|
#if FUSB302_USE_OS == 1
|
||||||
fusb302_dev.delay_ms = osDelay;
|
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) {
|
if (FUSB302_init(&fusb302_dev) == FUSB302_SUCCESS && FUSB302_get_ID(&fusb302_dev, 0, 0) == FUSB302_SUCCESS) {
|
||||||
PD_protocol_init(&pd_protocol);
|
PD_protocol_init(&pd_protocol);
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -69,6 +69,12 @@ void MX_GPIO_Init(void)
|
|||||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||||
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
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 */
|
/* USER CODE BEGIN 2 */
|
||||||
|
|||||||
@@ -10,8 +10,6 @@
|
|||||||
|
|
||||||
/* Private variables ---------------------------------------------------------*/
|
/* Private variables ---------------------------------------------------------*/
|
||||||
|
|
||||||
uint8_t timer_flag = 0;
|
|
||||||
|
|
||||||
/* Private function prototypes -----------------------------------------------*/
|
/* Private function prototypes -----------------------------------------------*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -24,12 +22,11 @@ void PDUFPTask(void *argument)
|
|||||||
// FUSB init
|
// FUSB init
|
||||||
fusb302_dev_init();
|
fusb302_dev_init();
|
||||||
// set
|
// set
|
||||||
PD_protocol_set_power_option(&pd_protocol, PD_POWER_OPTION_MAX_9V);
|
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), true);
|
PD_protocol_set_PPS(&pd_protocol, PD_V(8.4), PD_A(2.0), false);
|
||||||
while(1)
|
while(1)
|
||||||
{
|
{
|
||||||
timer_flag = fusb302_timer();
|
if (fusb302_timer() || HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_4) == GPIO_PIN_RESET) {
|
||||||
if (timer_flag) {
|
|
||||||
FUSB302_event_t FUSB302_events = 0;
|
FUSB302_event_t FUSB302_events = 0;
|
||||||
for (uint8_t i = 0; i < 3 && FUSB302_alert(&fusb302_dev, &FUSB302_events) != FUSB302_SUCCESS; i++) {}
|
for (uint8_t i = 0; i < 3 && FUSB302_alert(&fusb302_dev, &FUSB302_events) != FUSB302_SUCCESS; i++) {}
|
||||||
if (FUSB302_events) {
|
if (FUSB302_events) {
|
||||||
@@ -37,6 +34,6 @@ void PDUFPTask(void *argument)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
osDelay(100);
|
osDelay(50);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user