I came across an older demo that's in the process of being updated for SSP 1.2, located here (warning, the SSP 1.1.0 version doesn't fit but the 1.2 version is in the process of being published at the time of this post!): www.renesas.com/.../D6000188.html It enables the DK to act as a swipe to open, by first starting your fingers on the far left and it tracks your finger across the slider and upon completion will indicate open by illuminating the LEDs from dim to very bright via PWM. It also allows you to indicate a button press by illuminating two LEDs depending upon what button to press. However, let's say instead of a swipe to open (like an iPhone) you wanted to use the slider in a different way- to control the LED brightness via a PWM! A few simple modifications allow you to do just that. First thing you'll need to do is add the GPT timer module by selecting 'driver > timers > timer driver on r_gpt' and properly configure it, I used the following configuration- you'll want to add it to the CTSU thread. Next you'll need to modify the pin/peripheral such that instead of a normal GPIO function you'll get the peripheral function out of GPT2. For the LED to control, we're going to be targeting the red led, which is port 5 pin 1, pin 50, or GTIOC2B_B depending upon how you want to refer to it. A quick screenshot is shown below. Not shown, but is easy to do is to switch the port (P501) to peripheral mode. After setting this up, we just need to add a little bit of code to start the gpt timer: void pwmStart(void){ ssp_err_t error_code = g_timer0.p_api->open(g_timer0.p_ctrl, g_timer0.p_cfg); if( (error_code) !=SSP_SUCCESS) { while(1); } g_timer0.p_api->dutyCycleSet(g_timer0.p_ctrl,D_FIFTY_PERCENT,TIMER_PWM_UNIT_PERCENT,50); } With autostart enabled, we only need to call the open api, and set the duty cycle to 50 (percent) and choose output pin 50. And place the function call in the ctsu_thread_entry function under the /*TODO*/ comment. Finally, all that's left is to modify the slider function (CB_Self_Slider_0) to control the duty cycle to the LED instead of controlling the PWM function. To do this we need to normalize the slider to a percentage duty cycle (we just need to divide the current slider position, by the number of possible positions which is contained in the SIZEOFBUFFER define and multiply by 100). An example of how to do this quick and dirty is shown below: percent_duty_cycle = (uint8_t)(((float)(p_args->current_position)/(float)SIZEOFBUFFER)*100.0); And all we have to do this place this inside of the else statement under the TOUCHED and HELD switch case statements. An example of how this is done is shown below (you will need to gut the existing code inside of there, and do it in the HELD and TOUCHED switch cases): case SF_TOUCH_CTSU_SLIDER_STATE_TOUCHED: case SF_TOUCH_CTSU_SLIDER_STATE_TOUCHED | SF_TOUCH_CTSU_SLIDER_STATE_MULTI_TOUCH: if(0 != (p_args->event & (uint32_t)SF_TOUCH_CTSU_SLIDER_STATE_MULTI_TOUCH)) { } else { percent_duty_cycle = (uint8_t)(((float)(p_args->current_position)/(float)SIZEOFBUFFER)*100.0); } break; Lastly, at the end of the function, we just need to call the gpt api to update the duty cycle with the new duty cycle value (bonus points for clipping it to 100%) at the end of the function. g_timer0.p_api->dutyCycleSet(g_timer0.p_ctrl,percent_duty_cycle,TIMER_PWM_UNIT_PERCENT,50); And just like that, you have the ability to modify the existing project to control the LED brightness (or the speed to a brushed DC motor, for example) via PWM. Hope this helps anyone with the DK-S124.
↧