/*
 * led_user.c
 *
 *  Created on: Aug 3, 2023
 *      Author: true
 */


#include "hk32f030m.h"
#include <stdint.h>



#define USERLED_IPORT	GPIOC		// i2c port/pin
#define USERLED_IPIN	6

#define USERLED_LPORT	GPIOD		// led port/pin
#define USERLED_LPIN	7



void userled_init()
{

}

void userled_set(uint8_t brightness)
{
	if (!brightness) {
		USERLED_IPORT->MODER &= ~(0x3           << (USERLED_IPIN * 2));
		USERLED_IPORT->MODER |=  (GPIO_Mode_IN  << (USERLED_IPIN * 2));

		USERLED_LPORT->BRR    =  (1 << USERLED_LPIN);
	} else {
		// set i2c port low while LED is lit
		USERLED_IPORT->MODER &= ~(0x3           << (USERLED_IPIN * 2));
		USERLED_IPORT->MODER |=  (GPIO_Mode_OUT << (USERLED_IPIN * 2));
		USERLED_IPORT->BRR    =  (1 << USERLED_IPIN);

		USERLED_LPORT->BSRR   =  (1 << USERLED_LPIN);
	}
}
