ch32-rs / ch58x-hal

HAL for the CH583/CH582/CH581 family of microcontrollers. BLE 5.3, RISC-V Qingke V4.
Apache License 2.0
32 stars 7 forks source link

Feature request: Is IR transmitter possible with ch582F chip in Rust? #4

Open happytm opened 10 months ago

happytm commented 10 months ago

As you know I am very new to Rust language. With your help I just setup Rust environment couple of days ago.

Now I have new feature request. I was searching for IR transmitter solution for CH582F in Rust but could not find any. But came across a repository which implements IR transmitter for ATTiny13A micro controller and goes into detail of it's functionality. I think he uses timer functionality of ATTiny13A to create any custom IR protocol codes. The repository is linked below:

https://github.com/wagiminator/ATtiny13-TinyRemote?tab=readme-ov-file

He also have IR receiver implemented on ATTiny13A chip in another repository:

https://github.com/wagiminator/ATtiny13-TinyDecoder

His blog linked below is treasure trove for ATTiny devices:

http://www.technoblogy.com/show?24A9

One benefit of CH582F is it's builtin BLE. This makes it possible to use smartphone instead of buttons in above project to control any device in vicinity of IR transmitter. That can make very low cost home automation system.

Is it possible to implement this in Rust?

Thank you.

andelf commented 10 months ago

I'll update this when Timers are implemented. Currently, a bit-bang implementation is possible.

happytm commented 10 months ago

OK thanks. I will be waiting.

andelf commented 10 months ago

Thanks. Could you provide a similar example in C/CPP? For the IR transmitter, I think the following API should be sufficient for sending a well-formed protocol:

happytm commented 9 months ago

I have no similar example in C/CPP but there is a project in assembly linked below:

https://www.sbprojects.net/projects/ir-repeater/index.php

At the end of that page there is download link to download code and circuit schematic for PIC micro controller.

Thanks.

Thanks.

imi415 commented 9 months ago

Hi @happytm,

At the end of that page there is download link to download code and circuit schematic for PIC micro controller.

This project you shared is using an NE555 to generate the 38kHz carrier frequency and doing a ASK modulation using a MOSFET. On MCUs with PWM output capabilities, the circuit can be further simplified and the time base circuit can be removed.

To control your IR diode using a PWM capable pin, set the PWM parameter to 20% duty with 38kHz frequency, then modulate the carrier signal output by configuring GPIO AF to GPIO/TIMER according to the baseband signal.

You have already shared the specifications of the IR remote protocol:

His blog linked below is treasure trove for ATTiny devices:

http://www.technoblogy.com/show?24A9

So what you have to do next is implementing the protocol by looking at the "Protocols" chapter of the above blog post.

Regards, Yilin Sun

happytm commented 9 months ago

@imi415 He is not using 555 timer at all. He is saying 555 timer is bad and reliable so he used PIC microcontroller.

I am new to Rust so if you can provide sample code for encoder/decoder I will appreciate it.

Thanks.

happytm commented 9 months ago

There is IR implementation for Rust but for other microcontrollers if it is any help to port it to CH582 chip.

https://github.com/jkristell/infrared

Thanks.