ch58x-hal icon indicating copy to clipboard operation
ch58x-hal copied to clipboard

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

Open happytm opened this issue 1 year ago • 7 comments

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.

happytm avatar Jan 06 '24 22:01 happytm

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

andelf avatar Feb 03 '24 18:02 andelf

OK thanks. I will be waiting.

happytm avatar Feb 04 '24 00:02 happytm

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:

  • PwmOut::send(data: &[u16]) for sending a series of pulses(duty) using current frequency
  • PwmIn::read(data: &mut [u16]) for receiving. with edge trigger support.

andelf avatar Feb 04 '24 02:02 andelf

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.

happytm avatar Feb 07 '24 23:02 happytm

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

imi415 avatar Feb 08 '24 00:02 imi415

@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 avatar Feb 08 '24 07:02 happytm

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.

happytm avatar Feb 08 '24 23:02 happytm