Contributed by WangChong, curated by Ai-Thinker
Today I'll share code for the M61 to receive infrared signals. The group keeps saying the SDK has updates, but I can't find any on GitHub. The SDK I'm currently using is the Bouffalo SDK, which I pulled down last night.

In the folder above, there is an example on how to use IR, i.e., the library shown below.

But group members may not have that many BL chips. The M61-32S chip is a BL616 (you can use different compile commands to compile firmware for different chips). So I modified its code so that after flashing, the IR remote can directly control the LED blinking (M61, BL616).
The expected result: each time a remote button is pressed, the blue LED toggles and the serial port outputs data.

The code:
#include "board.h"
#include "bflb_ir.h"
#include "bflb_gpio.h"
#include "bl616_glb.h"
#ifdef BL616
#define TEST_IR_RX
#endif
struct bflb_device_s *irrx;
struct bflb_device_s *gpio;
void toggle_gpio(void)
{
static int state = 1;
if (state) {
bflb_gpio_set(gpio, GPIO_PIN_15);
state = 0;
} else {
bflb_gpio_reset(gpio, GPIO_PIN_15);
state = 1;
}
}
/* main */
int main(void)
{
board_init();
gpio = bflb_device_get_by_name("gpio");
// initialize the GPIO pin
bflb_gpio_init(gpio, 11, (1 << 5) | (1 << (11)) | (0 << (12)));
// set the IR receive or send pin
GLB_IR_RX_GPIO_Sel((11));
// initialize the LED
bflb_gpio_init(gpio, GPIO_PIN_15, GPIO_OUTPUT | GPIO_PULLUP);
uint64_t rx_data;
uint8_t rx_len;
// configure IR receive
struct bflb_ir_rx_config_s rx_cfg;
irrx = bflb_device_get_by_name("irrx");
/* RX init */
rx_cfg.rx_mode = IR_RX_NEC;
// data check, must be enabled; 0x00 becomes 0xff after inversion
rx_cfg.input_inverse = true;
// filtering
rx_cfg.deglitch_enable = false;
bflb_ir_rx_init(irrx, &rx_cfg);
// enable receiving
bflb_ir_rx_enable(irrx, true);
while (1) {
/* Receive */
rx_len = bflb_ir_receive(irrx, &rx_data);
printf("Receive bit: %d, value: 0x%x\r\n", rx_len, rx_data);
printf("%d", ((rx_data & 0xff000000) >> 24));
if (((rx_data & 0xff000000) >> 24) == 0xba) {
toggle_gpio();
}
}
}
I won't paste the project files, because you need to set the SDK directory according to your own environment; just copy this code and run it.Have questions?
For other questions, please visit the unified discussion area: Ai-Thinker Discussions

