Skip to content

Commit

Permalink
Add MCUHWC_SetInfoLedPattern (#549)
Browse files Browse the repository at this point in the history
  • Loading branch information
kynex7510 authored Sep 15, 2024
1 parent cc5b884 commit 5f06a03
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 8 deletions.
32 changes: 24 additions & 8 deletions libctru/include/3ds/services/mcuhwc.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,25 @@
*/
#pragma once

typedef enum
typedef enum {
LED_NORMAL = 1, ///< The normal mode of the led
LED_SLEEP_MODE, ///< The led pulses slowly as it does in the sleep mode
LED_OFF, ///< Switch off power led
LED_RED, ///< Red state of the led
LED_BLUE, ///< Blue state of the led
LED_BLINK_RED, ///< Blinking red state of power led and notification led
} powerLedState;

typedef struct InfoLedPattern
{
LED_NORMAL = 1, ///< The normal mode of the led
LED_SLEEP_MODE, ///< The led pulses slowly as it does in the sleep mode
LED_OFF, ///< Switch off power led
LED_RED, ///< Red state of the led
LED_BLUE, ///< Blue state of the led
LED_BLINK_RED, ///< Blinking red state of power led and notification led
}powerLedState;
u8 delay; ///< Delay between pattern values, 1/16th of a second (1 second = 0x10)
u8 smoothing; ///< Smoothing between pattern values (higher = smoother)
u8 loopDelay; ///< Delay between pattern loops, 1/16th of a second (1 second = 0x10, 0xFF = pattern is played only once)
u8 blinkSpeed; ///< Blink speed, when smoothing == 0x00
u8 redPattern[32]; ///< Pattern for red component
u8 greenPattern[32]; ///< Pattern for green component
u8 bluePattern[32]; ///< Pattern for blue component
} InfoLedPattern;

/// Initializes mcuHwc.
Result mcuHwcInit(void);
Expand Down Expand Up @@ -66,6 +76,12 @@ Result MCUHWC_GetSoundSliderLevel(u8 *level);
*/
Result MCUHWC_SetWifiLedState(bool state);

/**
* @brief Sets the notification LED pattern
* @param pattern Pattern for the notification LED.
*/
Result MCUHWC_SetInfoLedPattern(const InfoLedPattern* pattern);

/**
* @brief Sets Power LED state
* @param state powerLedState State of power LED.
Expand Down
17 changes: 17 additions & 0 deletions libctru/source/services/mcuhwc.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <string.h>
#include <3ds/types.h>
#include <3ds/svc.h>
#include <3ds/synchronization.h>
Expand Down Expand Up @@ -114,6 +115,22 @@ Result MCUHWC_SetWifiLedState(bool state)
return (Result)cmdbuf[1];
}

Result MCUHWC_SetInfoLedPattern(const InfoLedPattern* pattern)
{
Result ret = 0;
u32 *cmdbuf = getThreadCommandBuffer();

cmdbuf[0] = IPC_MakeHeader(0x0A,25,0); // 0xA0640
cmdbuf[1] = ((u32)pattern->blinkSpeed << 24) | ((u32)pattern->loopDelay << 16) | ((u32)pattern->smoothing << 8) | pattern->delay;
memcpy(&cmdbuf[2], pattern->redPattern, sizeof(pattern->redPattern));
memcpy(&cmdbuf[10], pattern->greenPattern, sizeof(pattern->greenPattern));
memcpy(&cmdbuf[18], pattern->bluePattern, sizeof(pattern->bluePattern));

if(R_FAILED(ret = svcSendSyncRequest(mcuHwcHandle))) return ret;

return (Result)cmdbuf[1];
}

Result MCUHWC_GetSoundSliderLevel(u8 *level)
{
Result ret = 0;
Expand Down

0 comments on commit 5f06a03

Please sign in to comment.