Inline void set_port_pull(uint32_t reg, uint_t p, bool_t up) { if (up) { sil_wrw_mem((void*)GPIO_BSRR(reg), 0x01 << p); } else { sil_wrw_mem((void*)GPIO_BRR(reg), 0x01 << p); } }
UInt8 native_setLed(_UNUSED_ struct UjThread* t, _UNUSED_ struct UjClass* cls) { Boolean led = ujThreadPop(t); if (led) { GPIO_BSRR(GPIOB) = GPIO10; } else { GPIO_BRR(GPIOB) = GPIO10; } return UJ_ERR_NONE; }
void do_blink(void) { uint8_t i = 0; for (i = 0; i < 3; i++) { do_delay(); GPIO_BSRR(GPIOB) = GPIO10; do_delay(); GPIO_BRR(GPIOB) = GPIO10; } do_delay(); do_delay(); do_delay(); do_delay(); for (i = 0; i < 10; i++) { do_delay(); GPIO_BSRR(GPIOB) = GPIO10; do_delay(); GPIO_BRR(GPIOB) = GPIO10; } }
int main(void) { //rcc_clock_setup_in_hsi_out_48mhz(); rcc_clock_setup_in_hse_8mhz_out_72mhz(); rcc_periph_clock_enable(RCC_GPIOB); gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO10); do_blink(); GPIO_BRR(GPIOB) = GPIO10; struct UjClass* mainClass = NULL; struct UjClass* objectClass; UInt32 threadH; UInt8 ret = ujInit(&objectClass); if(ret != UJ_ERR_NONE){ GPIO_BSRR(GPIOB) = GPIO10; while (true) {} } ret = ujRegisterNativeClass(&nativeCls_UC, objectClass, NULL); if(ret != UJ_ERR_NONE){ GPIO_BSRR(GPIOB) = GPIO10; while (true) {} } ret = ujLoadClass(0, &mainClass); if(ret != UJ_ERR_NONE){ GPIO_BSRR(GPIOB) = GPIO10; while (true) {} } ret = ujInitAllClasses(); if(ret != UJ_ERR_NONE){ GPIO_BSRR(GPIOB) = GPIO10; while (true) {} } //now classes are loaded, time to call the entry point threadH = ujThreadCreate(0); if(!threadH) { GPIO_BSRR(GPIOB) = GPIO10; while (true) {} } UInt8 h = ujThreadGoto(threadH, mainClass, "main", "()V"); if(h == UJ_ERR_METHOD_NONEXISTENT) { GPIO_BSRR(GPIOB) = GPIO10; while (true) {} } while(ujCanRun()) { h = ujInstr(); if(h != UJ_ERR_NONE) { GPIO_BSRR(GPIOB) = GPIO10; while (true) {} } } GPIO_BSRR(GPIOB) = GPIO10; while (true) {} }
void led_off(void) { GPIO_BRR(GPIOB) = GPIO10; }
/** @brief Clear a Group of Pins Atomic Clear one or more pins of the given GPIO port to 0 in an atomic operation. @param[in] gpioport Unsigned int32. Port identifier @ref gpio_port_id @param[in] gpios Unsigned int16. Pin identifiers @ref gpio_pin_id If multiple pins are to be changed, use logical OR '|' to separate them. */ void gpio_clear(u32 gpioport, u16 gpios) { GPIO_BRR(gpioport) = gpios; }