Skip to content

Commit 5f06a03

Browse files
authored
Add MCUHWC_SetInfoLedPattern (#549)
1 parent cc5b884 commit 5f06a03

2 files changed

Lines changed: 41 additions & 8 deletions

File tree

libctru/include/3ds/services/mcuhwc.h

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,25 @@
44
*/
55
#pragma once
66

7-
typedef enum
7+
typedef enum {
8+
LED_NORMAL = 1, ///< The normal mode of the led
9+
LED_SLEEP_MODE, ///< The led pulses slowly as it does in the sleep mode
10+
LED_OFF, ///< Switch off power led
11+
LED_RED, ///< Red state of the led
12+
LED_BLUE, ///< Blue state of the led
13+
LED_BLINK_RED, ///< Blinking red state of power led and notification led
14+
} powerLedState;
15+
16+
typedef struct InfoLedPattern
817
{
9-
LED_NORMAL = 1, ///< The normal mode of the led
10-
LED_SLEEP_MODE, ///< The led pulses slowly as it does in the sleep mode
11-
LED_OFF, ///< Switch off power led
12-
LED_RED, ///< Red state of the led
13-
LED_BLUE, ///< Blue state of the led
14-
LED_BLINK_RED, ///< Blinking red state of power led and notification led
15-
}powerLedState;
18+
u8 delay; ///< Delay between pattern values, 1/16th of a second (1 second = 0x10)
19+
u8 smoothing; ///< Smoothing between pattern values (higher = smoother)
20+
u8 loopDelay; ///< Delay between pattern loops, 1/16th of a second (1 second = 0x10, 0xFF = pattern is played only once)
21+
u8 blinkSpeed; ///< Blink speed, when smoothing == 0x00
22+
u8 redPattern[32]; ///< Pattern for red component
23+
u8 greenPattern[32]; ///< Pattern for green component
24+
u8 bluePattern[32]; ///< Pattern for blue component
25+
} InfoLedPattern;
1626

1727
/// Initializes mcuHwc.
1828
Result mcuHwcInit(void);
@@ -66,6 +76,12 @@ Result MCUHWC_GetSoundSliderLevel(u8 *level);
6676
*/
6777
Result MCUHWC_SetWifiLedState(bool state);
6878

79+
/**
80+
* @brief Sets the notification LED pattern
81+
* @param pattern Pattern for the notification LED.
82+
*/
83+
Result MCUHWC_SetInfoLedPattern(const InfoLedPattern* pattern);
84+
6985
/**
7086
* @brief Sets Power LED state
7187
* @param state powerLedState State of power LED.

libctru/source/services/mcuhwc.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include <string.h>
12
#include <3ds/types.h>
23
#include <3ds/svc.h>
34
#include <3ds/synchronization.h>
@@ -114,6 +115,22 @@ Result MCUHWC_SetWifiLedState(bool state)
114115
return (Result)cmdbuf[1];
115116
}
116117

118+
Result MCUHWC_SetInfoLedPattern(const InfoLedPattern* pattern)
119+
{
120+
Result ret = 0;
121+
u32 *cmdbuf = getThreadCommandBuffer();
122+
123+
cmdbuf[0] = IPC_MakeHeader(0x0A,25,0); // 0xA0640
124+
cmdbuf[1] = ((u32)pattern->blinkSpeed << 24) | ((u32)pattern->loopDelay << 16) | ((u32)pattern->smoothing << 8) | pattern->delay;
125+
memcpy(&cmdbuf[2], pattern->redPattern, sizeof(pattern->redPattern));
126+
memcpy(&cmdbuf[10], pattern->greenPattern, sizeof(pattern->greenPattern));
127+
memcpy(&cmdbuf[18], pattern->bluePattern, sizeof(pattern->bluePattern));
128+
129+
if(R_FAILED(ret = svcSendSyncRequest(mcuHwcHandle))) return ret;
130+
131+
return (Result)cmdbuf[1];
132+
}
133+
117134
Result MCUHWC_GetSoundSliderLevel(u8 *level)
118135
{
119136
Result ret = 0;

0 commit comments

Comments
 (0)